I am using number_to_human to print 4 Million. I was wondering if there is a method that will add the $ to the front of the number? I run into issues when I have a negative number. If I just throw a $ in front I will get $-4 Million they want -$4 Million
It's builtin Rails:
number_to_currency(number_to_human(-4000000))
# => "-$4 Million"
The big advantage in using convention is that, when you need i18n, you just have to pass the locale:
number_to_currency(number_to_human(-4000000), locale: 'en-EU')
# => "-4 Million €"
Its interesting thing and If It would help to anybody:
How to Present thousands as "K", millions as "M" in ruby for that,
just follow the steps
Include NumberHelper in controller at top
include ActionView::Helpers::NumberHelper
Use this number_to_human Helper and pass the value, This will convert the value
<%= number_to_human(5223654) %>
Paste this code in en.yml to get it working
en:
number:
human:
decimal_units:
format: "%n%u"
units:
unit: ""
thousand: K
million: M
billion: B
trillion: T
quadrillion: Q
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With