cbarbal
October 12, 2006, 12:18pm
1
I have two formulas that work correctly, one calculates the discount and the other the total.
dto_importe
if ( dto >0 )
{
var importe = importe_bruto * ( dto / 100);
var total = importe.toFixed(2);
//var total = utils.numberFormat(importe, 2);
return total;
}
else
{
return null
}
total_linea
if ( importe_bruto>0 )
{
var total = importe_bruto - dto_importe
return total;
}
else
{
return null
}
But change in "dto_importe " var total = importe.toFixed(2) by var total = utils.numberFormat(importe, 2), does not work the formula “total_linea”.
Because?
Carles Barbal
ROCLASI
October 12, 2006, 12:46pm
2
Hi Carles,
I am surprised that .toFixed() works at all for you.
Both .toFixed() and utils.numberFormat() return a string.
And in your ‘total_linea’ calculation you try to subtract with a string value. It won’t work.
Make sure you return a number in your ‘dto_importe’ calculation by using the utils.stringToNumber() function like so: ```
return utils.stringToNumber(total);
This way your 'total_linea; calculation will be calculating with a correct value type.
Hope this helps.
Hi Robert,
A explanation. They are numeric fields calculated and stored. It represents that they store like string instead of numbers in database?.
Utils.numberFormat() it works like Round() of FileMaker not like .toFixed(), that according to which number does not round well.
I sorry my English is very bad .
Carles Barbal
Hi Carles,
cbarbal:
A explanation. They are numeric fields calculated and stored. It represents that they store like string instead of numbers in database?.
That is correct. Those functions return string values.
cbarbal:
Utils.numberFormat() it works like Round() of FileMaker not like .toFixed(), that according to which number does not round well.
Please take a look at the following threads:
http://forum.servoy.com/viewtopic.php?t=4910
http://forum.servoy.com/viewtopic.php?t=5919
http://forum.servoy.com/viewtopic.php?t=5919
Hope this helps.
Hi Robert,
This functions work like Round of FileMaker.
utils.stringToNumber(utils.numberFormat(total, 2)) /100
Thanks for your aid.
Carles Barbal