|
BcMath\Number::round任意精度数値を丸める 説明
public BcMath\Number BcMath\Number::round(int
$precision = 0, RoundingMode $mode = RoundingMode::HalfAwayFromZero)
$this を、指定した パラメータ
戻り値結果を新しい BcMath\Number オブジェクトとして返します。 エラー / 例外
このメソッドは、無効な 例例1 BcMath\Number::round の例 上の例の出力は以下となります。
object(BcMath\Number)#2 (2) {
["value"]=>
string(1) "3"
["scale"]=>
int(0)
}
object(BcMath\Number)#3 (2) {
["value"]=>
string(1) "4"
["scale"]=>
int(0)
}
object(BcMath\Number)#4 (2) {
["value"]=>
string(1) "4"
["scale"]=>
int(0)
}
object(BcMath\Number)#5 (2) {
["value"]=>
string(1) "4"
["scale"]=>
int(0)
}
object(BcMath\Number)#6 (2) {
["value"]=>
string(4) "5.05"
["scale"]=>
int(2)
}
object(BcMath\Number)#7 (2) {
["value"]=>
string(4) "5.06"
["scale"]=>
int(2)
}
object(BcMath\Number)#8 (2) {
["value"]=>
string(3) "300"
["scale"]=>
int(0)
}
object(BcMath\Number)#9 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}
object(BcMath\Number)#10 (2) {
["value"]=>
string(3) "700"
["scale"]=>
int(0)
}
object(BcMath\Number)#11 (2) {
["value"]=>
string(4) "1000"
["scale"]=>
int(0)
}
例2
BcMath\Number::round で異なる 上の例の出力は以下となります。
object(BcMath\Number)#2 (2) {
["value"]=>
string(7) "123.450"
["scale"]=>
int(3)
}
object(BcMath\Number)#3 (2) {
["value"]=>
string(6) "123.45"
["scale"]=>
int(2)
}
object(BcMath\Number)#4 (2) {
["value"]=>
string(5) "123.5"
["scale"]=>
int(1)
}
object(BcMath\Number)#5 (2) {
["value"]=>
string(3) "123"
["scale"]=>
int(0)
}
object(BcMath\Number)#6 (2) {
["value"]=>
string(3) "120"
["scale"]=>
int(0)
}
object(BcMath\Number)#7 (2) {
["value"]=>
string(3) "100"
["scale"]=>
int(0)
}
object(BcMath\Number)#8 (2) {
["value"]=>
string(1) "0"
["scale"]=>
int(0)
}
例3
BcMath\Number::round で異なる 上の例の出力は以下となります。
Rounding modes with 9.5
object(BcMath\Number)#3 (2) {
["value"]=>
string(2) "10"
["scale"]=>
int(0)
}
object(BcMath\Number)#5 (2) {
["value"]=>
string(1) "9"
["scale"]=>
int(0)
}
object(BcMath\Number)#7 (2) {
["value"]=>
string(2) "10"
["scale"]=>
int(0)
}
object(BcMath\Number)#9 (2) {
["value"]=>
string(1) "9"
["scale"]=>
int(0)
}
object(BcMath\Number)#11 (2) {
["value"]=>
string(1) "9"
["scale"]=>
int(0)
}
object(BcMath\Number)#13 (2) {
["value"]=>
string(2) "10"
["scale"]=>
int(0)
}
object(BcMath\Number)#15 (2) {
["value"]=>
string(1) "9"
["scale"]=>
int(0)
}
object(BcMath\Number)#17 (2) {
["value"]=>
string(2) "10"
["scale"]=>
int(0)
}
Rounding modes with 8.5
object(BcMath\Number)#1 (2) {
["value"]=>
string(1) "9"
["scale"]=>
int(0)
}
object(BcMath\Number)#15 (2) {
["value"]=>
string(1) "8"
["scale"]=>
int(0)
}
object(BcMath\Number)#13 (2) {
["value"]=>
string(1) "8"
["scale"]=>
int(0)
}
object(BcMath\Number)#11 (2) {
["value"]=>
string(1) "9"
["scale"]=>
int(0)
}
object(BcMath\Number)#9 (2) {
["value"]=>
string(1) "8"
["scale"]=>
int(0)
}
object(BcMath\Number)#7 (2) {
["value"]=>
string(1) "9"
["scale"]=>
int(0)
}
object(BcMath\Number)#5 (2) {
["value"]=>
string(1) "8"
["scale"]=>
int(0)
}
object(BcMath\Number)#3 (2) {
["value"]=>
string(1) "9"
["scale"]=>
int(0)
}
例4
BcMath\Number::round で 上の例の出力は以下となります。
Using RoundingMode::HalfAwayFromZero with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.6"
["scale"]=>
int(1)
}
object(BcMath\Number)#5 (2) {
["value"]=>
string(4) "-1.6"
["scale"]=>
int(1)
}
Using RoundingMode::HalfTowardsZero with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.5"
["scale"]=>
int(1)
}
object(BcMath\Number)#6 (2) {
["value"]=>
string(4) "-1.5"
["scale"]=>
int(1)
}
Using RoundingMode::HalfEven with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.6"
["scale"]=>
int(1)
}
object(BcMath\Number)#7 (2) {
["value"]=>
string(4) "-1.6"
["scale"]=>
int(1)
}
Using RoundingMode::HalfOdd with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.5"
["scale"]=>
int(1)
}
object(BcMath\Number)#8 (2) {
["value"]=>
string(4) "-1.5"
["scale"]=>
int(1)
}
Using RoundingMode::TowardsZero with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.5"
["scale"]=>
int(1)
}
object(BcMath\Number)#9 (2) {
["value"]=>
string(4) "-1.5"
["scale"]=>
int(1)
}
Using RoundingMode::AwayFromZero with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.6"
["scale"]=>
int(1)
}
object(BcMath\Number)#10 (2) {
["value"]=>
string(4) "-1.6"
["scale"]=>
int(1)
}
Using RoundingMode::NegativeInfinity with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.5"
["scale"]=>
int(1)
}
object(BcMath\Number)#11 (2) {
["value"]=>
string(4) "-1.6"
["scale"]=>
int(1)
}
Using RoundingMode::PositiveInfinity with 1 decimal digit precision
object(BcMath\Number)#4 (2) {
["value"]=>
string(3) "1.6"
["scale"]=>
int(1)
}
object(BcMath\Number)#12 (2) {
["value"]=>
string(4) "-1.5"
["scale"]=>
int(1)
}
参考
|