This topic is locked

Calculate Values On The Fly

4/2/2013 10:48:07 AM
PHPRunner General questions
L
leodutra author

Hi,
Testing this example I came across a problem, if you enter 99.99 works but does not work if you enter 99,99

var ctrlPrice = Runner.getControl(pageid, 'Price');
var ctrlQuantity = Runner.getControl(pageid, 'Quantity');
var ctrlTotal = Runner.getControl(pageid, 'Total');

function func() {
ctrlTotal.setValue(Number(ctrlPrice.getValue()) * Number(ctrlQuantity.getValue()));
};

ctrlPrice.on('keyup', func);
ctrlQuantity.on('keyup', func);


By default in Brazil the decimal separator is a comma, but when I type values ​​with comma appears the error "NaN". I need the calculation is done with comma.

Sergey Kornilov admin 4/2/2013

The proper decimal separator in Javascript is dot.

More info:

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/parseFloat
If you want to accept comma as a decimal separator if you need to process input manually replacing commas with dots.