Decimal fields are shown as string representation of floats

To reproduce:

  • create an entry with a decimal field, enter some value (e.g. 3.17)
  • lesana show

it will show '3.1699999999999999289457264239899814128875732421875' as the value for that field.

(The same thing happens in the lesanaweb templates).

Assigned to
1 year, 11 months ago
11 months ago

Elena ``of Valhalla'' 1 year, 10 months ago · edit

This is caused by the fact that the value is loaded as a float by the yaml reader, before lesana interacts with it, and thus it is converted to Decimal after it has been represented as a binary floating point.

#The workaround is to store such values as strings with explicit quoting (e.g. cost: '1.99') so that it is correctly converted to Decimal without loss of precision.

Elena ``of Valhalla''

~valhalla 11 months ago

From commit 4023903e there is also a property precision to force rounding all values for a decimal field to a certain number of decimal digits.

Register here or Log in to comment, or comment via email.