1
0

Displaying quantities with fixed precision/MFU unit removed

This commit is contained in:
cryptogopher
2020-04-28 16:05:42 +02:00
parent dfa20a55d1
commit 3418af87c1
5 changed files with 44 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
module BodyTrackersHelper
def format_value(value)
def format_value(value, precision=2, mfu_unit=nil)
amount, unit = value
case
when amount.nil?
@@ -7,7 +7,8 @@ module BodyTrackersHelper
when amount.nan?
'?'
else
"#{amount} [#{unit.shortname || '-'}]"
unit_desc = unit != mfu_unit ? unit && " [#{unit.shortname}]" || ' [-]' : ''
"%.#{precision}f%s" % [amount, unit_desc]
end
end