With Rails' number_to_human_size
you can just do a gsub
to replace values in the suffix.
number_to_human_size(1234567890).gsub(/(Bytes?|B$)/,'b/s')
# => "1.15 Gb/s"
Pregunta
I have been using the excellent number_to_human_size
ActionView::Helper
and I was wondering if there is any way to change the output unit notation:
The default behavior is to output the units in Bytes, KB, MB, etc while I would like to see Bit, Kb, Mb etc.
The number conversion is correct, I only want to change the unit name. I have figured out that using locales could be a solution and have added this in my en.yml
:
en:
storage_units:
format: "%n %u"
units:
byte:
one: "b/s"
other: "b/s"
kb: "Kb/s"
mb: "Mb/s"
gb: "Gb/s"
tb: "Tb/s"
...but doesn't seem to work.
Has anybody ever dealt with this challenge?
Thanks in advance,
Petros
Solución
With Rails' number_to_human_size
you can just do a gsub
to replace values in the suffix.
number_to_human_size(1234567890).gsub(/(Bytes?|B$)/,'b/s')
# => "1.15 Gb/s"