2009/6/3 Craig White <[email protected]>: > ... > I forgot about to_f because frankly, I never used it. I primarily am > concerned with view code here so I had just stuck that code to extend > the Float class (which worked so well in 1.2.x)... > > class Float > def to_fl(digits) > sprintf("%.#{digits}f",self) > end > end > > and I could get a fixed number of digits whenever I wanted. Apparently > this is like a very ineffective way to go about things in 2.3.x and to_f > gives me whatever decimal places it believes are significant so I'm sort > of trying to figure out how to locate the magic genie again. > > Craig >
I am not sure whether you still have a problem. It is not strictly correct to say that to_f gives me whatever decimal places it believes are significant. A float will always contain as many digits as it can hold. Is the problem that you wish to display it to a certain number of digits? If so then you can use sprintf. Alternatively of course there is the question of whether you need to convert it to a float in the first place. Can you just keep it as BigDecimal? Colin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

