to_f cuts numbers : BigDecimal « Number « Ruby






to_f cuts numbers


require 'bigdecimal'

nm = "0.123456789012345678901234567890123456789"
nm.to_f                                            # => 0.123456789012346
BigDecimal(nm).to_s                                # => "0.123456789012345678901234567890123456789E0"

 








Related examples in the same category

1.Big decimal calculation
2.Calculation on BigDecimal in a function
3.precs of BigDecimal
4.Convert big decimal to string
5.split a big number
6..to_s("F")
7.Convert BigDecimal to string
8.Add value to BigDecimal
9.Round a BigDecimal
10.Get the square root for a BigDecimal
11.PI in BigDecimal