0

In my typo3 extension I got a double value saved via backend. I want to put this value out in the frontend.

I want the double to be formated to use the german ',' as decimal seperator (and a max precision of 1). So I used f:format.number viewhelper to set this. However that fluid helper ist setting fixed decimals. I want dynamic decimals, as in I do not want any trailing 0s. 4.0 ought to be shown as 4. If I do not use the viewhelper (thus outputting the raw data) the behaviour is as desired. 4.0 shows as 4, however it also does show 4.5 as 4.5 not as 4,5.

Is there a way to 'unfix' the decimals in the viewhelper? I also tried to wrap my output in if conditions to check via modula, but this never returns a positive.

How do I output formated doubles on a precision without trailing zeros?

user3154108
  • 1,264
  • 13
  • 23

1 Answers1

3

For just one digit (like in your example) the following code worked for me. For a double, you have to nest another if-condition in the else case since there is no else-if in fluid.

<f:if condition="{number} == {number -> f:format.number(decimals: 0)}">
  <f:then>
    <f:format.number decimals="0" decimalSeparator=",">{number}</f:format.number>
  </f:then>
  <f:else>
     <f:format.number decimals="1" decimalSeparator=",">{number}</f:format.number>
  </f:else>
</f:if>
Volker
  • 31
  • 2