toFixed does not show

I have 2 number fields, num1 and num2.
num1 contains 100, num2 contains 3.

When I make a calculation:
return (num1 / num2).toFixed(2);
NOTHING is displayed in the field.

Anyone?

TIA
Stef

The toFixed method returns a string representation of a number in fixed-point notation.
So is your calculation return type a string? (we will add a better warning if type mismatch)

ok, clear.

But how do we have to round to 2 digits in formulas?
This is very important!

TIA,
Stef

Use this formula instead :

x = num1 / num2;
return Math.round(x * 100) / 100;

Harry

OK, thanks Harry!

I figured this out as well, but it smells like an old FM-workaround. Is there no other way?

be careful.. Math.round rounds to the nearest integer.

If you need calcs with decimals you can also do:
return parseFloat ( (num1 / num2).toFixed(2) );

NOTE:
Assuming num1 and num2 are NUMBERS,
why don’t you just do
return (num1 / num2)
…and set the field format property to #.##

You could try :

x = num1 / num2;
return parseFloat(x.toFixed(2));

Here, you are just corecing the string result back into a number.