Home Ruby on rails big decimal value format not correct
Reply: 1

Ruby on rails big decimal value format not correct

Fahad
1#
Fahad Published in 2017-11-09 14:03:32Z

Big Decimal not showing value in numbers

a = BigDecimal.new("100.55")
a = * a * a
puts "big decimal #{a}"

output

big decimal [#<BigDecimal:ad5a6e8,'0.101103025E5',18(45)>]

How i can display it in proper format just like 12345.236

Junan Chakma
2#
Junan Chakma Reply to 2017-11-09 16:46:06Z

You can use to_s('F') method to convert it to float.

a = BigDecimal.new("100.55")
a = a * a
puts "big decimal #{a.to_s('F')}"
=> big decimal 10110.3025

Thanks @stefan for suggesting to use to_s('F') method instead of to_f.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.306983 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO