Homey Community Forum

Formatting number to 2 digits; just cosmetics ;-)

Hi,

I use the ‘Wasmachine’ flow to be noticed when the washingmachine has finished.
As an addition i also calcultate the costs of the power used.
With mathjs i round this calculation to 2 digits behind the separator.

Sometimes the calculation gives 20 cents. This is noted as € 0,2 in the message i send to myself.
Just for cosmetic reasons: Is there a way to format this into € 0,20 (2 digits so with the 0 added) in mathjs ? (number to string)
Like something as: usedpower$ = format$(number, € ##,00)

Peter

If Homey supports all of MathJS, you should be able to use this:

format(VALUE, { precision: 2 })

This will also perform the rounding operation.

@robertklep

Thanks for the quick repsonse; unfortunatly it does not work; Homey does not recognize ‘format’.

Yhx
Peter

Maybe round will work:
From @Canedje:
something like this wil work:
{{round (Energiekosten vandaag,2)}}

the 2 means 2 digits after the ,

in your case {{round(Target temperature,1)}}

He already used round(), but that function will drop any trailing zero’s.

Yep, using it already.

Round does not ‘format’ the number.

Peter

Maybe adding 0.000001 to the outcome, than Round and extract 0.000001. Maybe you have to round it again.