Avoid rounded with float numbers errors with javascript

0.7/0.001 = 699.9999999999999

Use Math.round() to avoid this.
This commit is contained in:
Jean-Baptiste Bellet
2021-09-14 10:45:31 +02:00
parent 82a8eed652
commit ba09618374
2 changed files with 8 additions and 1 deletions

View File

@@ -97,6 +97,13 @@ describe "Option Value Namer", ->
p.variant_unit_scale = scale
v.unit_value = 100 * scale
expect(namer.option_value_value_unit()).toEqual [100, unit]
it "generates right values for volume with rounded values", ->
unit = 'L'
p.variant_unit = 'volume'
p.variant_unit_scale = 1.0
v.unit_value = 0.7
expect(namer.option_value_value_unit()).toEqual [700, 'mL']
it "chooses the correct scale when value is very small", ->
p.variant_unit = 'volume'