This topic is locked
[SOLVED]

 formatting calculated values

1/16/2018 10:22:26 AM
ASPRunner.NET General questions
A
admin author

Hi Experts,
i am having a problem with values calculated on the fly!

In Javascript On load (add page) i calculate some values ex.

ctrlfscrap.setValue(((Number(ctrlfnetto.getValue()) * 0.40) / 36) * Number(ctrlfleasperiode.getValue()));


After calculation the value shown are ex. 60456.456789 - how do i format the value to 60456.46 ??
Thanks in advance
Michael

admin 1/16/2018

You can use Javascript's toFixed() function for this purpose.

var n = ((Number(ctrlfnetto.getValue()) * 0.40) / 36) * Number(ctrlfleasperiode.getValue());

n = Number(n).toFixed(2);

ctrlfscrap.setValue(n);


More info:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed

A
admin author 1/17/2018

Perfect Sergey - thank you