method
truncate
v2_4_6 -
Show latest stable
-
0 notes -
Class: BigDecimal
- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378 (0)
- 1_9_2_180 (-1)
- 1_9_3_125 (0)
- 1_9_3_392 (0)
- 2_1_10 (14)
- 2_2_9 (0)
- 2_4_6 (38)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
truncate(p1 = v1)
public
Truncate to the nearest integer (by default), returning the result as a BigDecimal.
BigDecimal('3.14159').truncate #=> 3 BigDecimal('8.7').truncate #=> 8 BigDecimal('-9.9').truncate #=> -9
If n is specified and positive, the fractional part of the result has no more than that many digits.
If n is specified and negative, at least that many digits to the left of the decimal point will be 0 in the result.
BigDecimal('3.14159').truncate(3) #=> 3.141 BigDecimal('13345.234').truncate(-2) #=> 13300.0