This topic is locked
[SOLVED]

 Too many decimel places

11/19/2012 10:24:02 PM
PHPRunner General questions
R
rustler45 author

I have field that is the result of a query:
r22lbs * r22rate AS labortotal
This result sometimes gives a number that has many decimel places such as 123.0002541
Is there a way within the query to limit the decimels to 2. I have the field setup in the editor as a number with 2 decimels but I keep getting these larger ones.
thanks!

C
cgphp 11/20/2012

Use the round function in the query:

ROUND(r22lbs * r22rate, 2) AS labortotal
R
rustler45 author 11/20/2012



Use the round function in the query:

ROUND(r22lbs * r22rate, 2) AS labortotal



That didnt work, but I think it is because I have a script that is loading the values on the fly. I found this on the forum and it works great but is it causing the long decimals?
var ctrlTravelRate = Runner.getControl(pageid, 'trate');

var ctrlTravelHours = Runner.getControl(pageid, 'tHours');

var ctrlTravelLabor = Runner.getControl(pageid, 'TTotal');
function func() {

ctrlTravelLabor.setValue(Number(ctrlTravelRate.getValue()) * Number(ctrlTravelHours.getValue()));
};
ctrlTravelRate.on('keyup', func);

ctrlTravelHours.on('keyup', func);
thanks

C
cgphp 11/20/2012

You have to put my code in the query replacing *r22lbs r22rate AS labortotal**

R
rustler45 author 11/20/2012



You have to put my code in the query replacing *r22lbs r22rate AS labortotal**


I realized that I did not need the queries, because I had put the scripts in for calculating the fields. I deleted the queries and I am using the script above. Is there a way to use the ROUND function on that script?

C
cgphp 11/20/2012

If you are dealing with float, use parseFloat instead of Number:

var ctrlTravelRate = Runner.getControl(pageid, 'trate');

var ctrlTravelHours = Runner.getControl(pageid, 'tHours');

var ctrlTravelLabor = Runner.getControl(pageid, 'TTotal');
function func() {

var num = parseFloat(ctrlTravelRate.getValue()) * parseFloat(ctrlTravelHours.getValue());

ctrlTravelLabor.setValue(num.toFixed(2));
};
ctrlTravelRate.on('keyup', func);

ctrlTravelHours.on('keyup', func);
R
rustler45 author 11/20/2012



If you are dealing with float, use parseFloat instead of Number:

var ctrlTravelRate = Runner.getControl(pageid, 'trate');

var ctrlTravelHours = Runner.getControl(pageid, 'tHours');

var ctrlTravelLabor = Runner.getControl(pageid, 'TTotal');
function func() {

var num = parseFloat(ctrlTravelRate.getValue()) * parseFloat(ctrlTravelHours.getValue());

ctrlTravelLabor.setValue(num.toFixed(2));
};
ctrlTravelRate.on('keyup', func);

ctrlTravelHours.on('keyup', func);



Fantastic!....thanks!