Decimals in number field get removed

Im using the number field to set prices and need the out put to be like 7.00 or 9.50 but the zeros and the decimal are be stripped off so it’s just display 7 or 9.5 in the front end. How can get it out putted as desired?

I can see this issue logged, and it appearts it was resovled, but even with the step option, it’s still stripping the zeros as above.

Are the zeros stripped from your content or just when outputting on the frontend?

I have “7.00” displaying in the panel field, but in the content file its just “7”

If i enter “7.35” then it gets stored correctly in content file.

I have gotten around it for now with…

  $number = $sarnie->price()->value();
  echo number_format((float)$number, 2, '.', '');

But it would be nice if i didnt have to. :slight_smile:

Have you tried toFloat()?

 $number = $sarnie->price()->toFloat();

I did yes, that still strips the zeros (or doesnt add them).

Ah, sorry, I missed that the zeros get stripped from the content file, so using toFloat() won’t add them again.

If I remember correctly, there was an issue once, maybe a won't fix because the zeros can be added using code. Have to check.

Edit: https://github.com/getkirby/kirby/issues/1748#issuecomment-541022656

I did see a couple of issues around it in github. For now, i think ill just turn the above solution into a custom field method, since i need this all over the place.

Sounds sensible :upside_down_face: