Support » Plugin: Calculated Fields Form » How to Round to Two Decimals?

Viewing 13 replies - 1 through 13 (of 13 total)
• Plugin Author codepeople

(@codepeople)

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.

Mikejuly

(@mikejuly)

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/balance-calculator/

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

Plugin Author codepeople

(@codepeople)

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.

wjweb

(@wjweb)

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/mijn-rijbewijs-info/bereken-je-prijs/

the equation i have now is 141+fieldname2*35.50+fieldname5+fieldname6

The outcome has to include 2 decimals.

thanks
WJ

Plugin Author codepeople

(@codepeople)

Hi,

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.

flabrea

(@flabrea)

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;
})()

Plugin Author codepeople

(@codepeople)

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);
})();

flabrea

(@flabrea)

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!

Plugin Author codepeople

(@codepeople)

Hi,

Use the “prec” operation. For example:

prec(10+20,2)

flabrea

(@flabrea)

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!

Plugin Author codepeople

(@codepeople)

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.

ryka

(@ryka)

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/give-me-variety-shopping-list/

And i am having the problem with all fields.

thank you in advance for your help

Plugin Author codepeople

(@codepeople)

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.

Viewing 13 replies - 1 through 13 (of 13 total)
• The topic ‘How to Round to Two Decimals?’ is closed to new replies.