ฟังก์ชัน bcsqrt() ใช้หาค่ารากที่สอง (square root) ของ arbitrary precision number รับค่าเป็น string และคืนค่ารากที่สองหลังปัดเศษตาม precision ที่ระบุ
รูปแบบการใช้งาน (Syntax)
string bcsqrt(string $num_string, int $scale = 0)
พารามิเตอร์
- $num_string – ตัวเลขที่ต้องการหารากที่สอง (string)
- $scale – จำนวนหลักทศนิยมในผลลัพธ์ (default 0)
ค่าที่คืนกลับ
คืนค่ารากที่สองเป็น string
ตัวอย่าง 1: ไม่ระบุ scale
<?php $num_string = "22"; $result = bcsqrt($num_string); echo "Output without scale value: " . $result; ?>
ผลลัพธ์
Output without scale value: 4
ตัวอย่าง 2: ระบุ scale = 3
<?php $num_string = "22"; $scale = 3; $result = bcsqrt($num_string, $scale); echo "Output with scale value: " . $result; ?>
ผลลัพธ์
Output with scale value: 4.690