Support » Plugins and Hacks » [Resolved] How to Round to Two Decimals?
[Resolved] How to Round to Two Decimals?

I am trying to round an output to 2 decimals – all I can achieve though is getting it to round to whole numbers.
Also, is there a way to hide fields?

Hi,
The Calculated Field allows you to use the operation “prec”. The operation “prec” requires two parameters, the second one determines the decimal digits. For example:
prec(0.333333, 2) will round the number to 0.33
Best regards.
Thanks for the quick response. That makes sense and I’ve made some pregress but I haven’t arrived yet.
My follow up question is how do I get the output of the form to round to two decimals. For example on this page:
http://domain4testing3.info/balancecalculator/
I want the ‘daily interest’ and other calculated fields to round to two decimals. I was able to achieve this by creating another ‘calculated field’ (at the bottom)with the parameters ‘prec(fieldname9, 2)’ per your instructions.
Is there a way to get the output to round, and if not, is there a way to hide the field I am rounding?
Thanks again.
MJ
Hi,
You have more than one Calculated Field on your page, but are using the operation “prec” in only one field, it is possible to use the Calculated Field in all of them.
Best regards.
Could you please explain how to set up the outcome to 2 decimals? I tried with the command prec but then i just get an error.
http://mijnrijles.info/mijnrijbewijsinfo/berekenjeprijs/
the equation i have now is 141+fieldname2*35.50+fieldname5+fieldname6
The outcome has to include 2 decimals.
thanks
WJHi,
You are in the correct direction, the command “prec” allow you to round a number to 2 decimals digits. Please, transform the equation as below:
prec((141+fieldname2*35.50+fieldname5+fieldname6),2)
If the trouble persist, please send us a contact through our website with a link to the webpage where the calculated field is used.
Best regards.
How can i round to 2 decimals in a function like
(function(){
var v;
if(fieldname7 == 546 && fieldname11 == 1) v = 142.2342;
if(fieldname7 == 546 && fieldname11 == 2) v = 190.4353;
return v*2;
})()Hi,
It is very simple. Exists the operation “prec”, that accept two parameters, the second one is the decimals numbers in the result. So, you equation would be:
(function(){
var v;
if(fieldname7 == 546 && fieldname11 == 1) v = 142.2342;
if(fieldname7 == 546 && fieldname11 == 2) v = 190.4353;
return prec(v*2,2);
})();Hi guys, i do have a little problem. I need all results to show up with two decimals. The way shown above works great when the result is rounded. But when i have something like “10 + 20”, of course nothing is rounded but i don’t see any decimals either. I need all results to end with .XY (like 10.00).
how can this be done? thanks!
Hi,
Use the “prec” operation. For example:
prec(10+20,2)
thanks for your fast answer! unfortunately it doesn’t work using…
(function(){ var v; if(fieldname6 >> 0) v = fieldname12; else v = 0; return prec(v*1,2); })()
any idea? thanks!
Hi,
I’ve checked your equation and it is working fine from my copy of plugin. Please, be sure to install the latest plugin’s update. (Install the plugin’s update preserves the forms created previously)
Another solution is change the structure of the equation like follows:
prec((function(){
var v;
if(fieldname6 >> 0) v = fieldname12;
else v = 0;return v;
})(),2)Best regards.
Hello Your information has been very helpful so far, and the plugin is very good, however I am struggling with the two decimal points. I am sure I am doing something wrong
The equation I have is
(fieldname2/65)*440)At the moment its 12 decimals points,
here is the link http://www.rykahealth.com/givemevarietyshoppinglist/And i am having the problem with all fields.
thank you in advance for your help
Hi,
The operation called “prec” (for precission), allow transform a number to the amount of decimal digits preferred. To display the result of your equation with two decimal digits, transform the equation like follow:
prec((fieldname2/65)*440, 2)
The second parameter in the equation is the number of decimal digits.
Best regards.
 The topic ‘[Resolved] How to Round to Two Decimals?’ is closed to new replies.