Thursday, 30 August 2012

Bigdecimal not exporting properly

When i was in need of generating my table's data into a report in excel format, i came across this issue.  I was using Spreadsheet gem for this purpose. The value of a particular cell contained lot of decimal places when i wanted it to be only 2 decimal place. After a lot of search, i found a good solution from rubyspreadsheet forum.


 amount = BigDecimal.new(".510283891298392")  
 sheet[0,4]= ("%7.2f" %amount).to_f         /*Converts the Big decimal to a value with 2 Floating points and write it to the (0,4)th cell */ 


If you want to know more, visit this link.

No comments:

Post a Comment