Page 1 of 1

Two decimals in a input

Posted: Sun Jul 06, 2014 6:34 pm
by Nicklas

Hello!
If I have a calculator, for example:

Two fields where the user (of the app) will input two numbers. When they click "Calculate" you get this: number1 / number2 = answer.

But if they for example write in "4 / 3", you will get: 1,333333333333333333-

My question is: How can I make the answer to: 1,334?
The javascript is in the Calculate-button:

var one, two
one = parseFloat(Appery("nu1").val());
two = parseFloat(Appery("nu2").val());

Appery("answe").val(one/two);


Two decimals in a input

Posted: Sun Jul 06, 2014 6:46 pm
by Evgene Karachevtsev

Hello Nicklas,

Hope this link will be useful: https://getsatisfaction.com/apperyio/...


Two decimals in a input

Posted: Sun Jul 06, 2014 7:01 pm
by Nicklas

So I should be: Appery("answer").val(one/two).toFixed(2);

That didn't work :S


Two decimals in a input

Posted: Sun Jul 06, 2014 7:09 pm
by Nicklas

But the link you showed me told me if I have 1, then I will get 1,00. But now I already have 1,3333333333333 and want: 1,334.


Two decimals in a input

Posted: Mon Jul 07, 2014 11:53 am
by Kateryna Grynko

Hi Nicklas,

Use the following code please:prevar res = one/two;
Appery("answer").val(res.toFixed(2));/pre


Two decimals in a input

Posted: Tue Jul 08, 2014 12:06 pm
by Nicklas

Thank you very much! :)