An alternative could be using

    number_to_currency(1234567890.50r)


Hugo Peixoto
--

https://hugopeixoto.net

On Sat, Jul 29, 2017 at 9:13 AM, Xavier Noria <f...@hashref.com> wrote:

> I wouldn't go as far as to say floats are *encouraged in general*, you
> gave an example of a questionable sample code, but also have
> counterexamples, for example in the type of price attributes in the AR
> migrations guide. Bottom line, all Rails core is aware of these gotchas,
> anything that could be misleading in this sense is probably an overlook.
>
> Problem is this helper rarely gets a literal, and
>
>     number_to_currency(1234567890.50)
>
> reads much better than
>
>     number_to_currency("1234567890.50".to_d)
>
> for my taste.
>
> It's easy to make something faster if you can make it wrong, and also to
> make it read better by stretching the truth just a little bit 😃.
>
> Maybe we could add a sentence saying "The following examples use floats,
> however, numbers representing money normally need and exact type like
> BigDecimal". Also open to better suggestions.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at https://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to