rounding problem
AnsweredHello Podio, what is the logical issue with this:
kostennetto = Math.round((kostennetto + mwst)/0.01)*0.01
kostennetto != kostenbrutto
Even if "kostennetto" is the exact same Number as "kostenbrutto", the calculation field sais it is not. When I put out each one it sais:
49,90
49,90
But when I put them out together (kostennetto + " " + kostenbrutto) it sais:
49,9000000000001 49,90
What is happening here? What did I do wrong?
-
Hi Jan,
this is just how floating point arithmetics work. See http://floating-point-gui.de/ for an explanation and ways around it.
Best,
StefandieKollaborateure.com - Podio Training+Consulting+Development — auch auf Deutsch
-
Hi Jan,
it's not a Podio problem. If you select "2 decimals" in the field options, it's only the option how many decimals should be shown. The number in the "background" which is used for the calculation is the full number with all decimals. So you have to fix the decimals with Javascript. You can try:
kostennetto = +(((kostennetto + mwst)/0.01)*0.01).toFixed(2)
Rainer
-
Jan,
I am using .toFixed(2) in a calculation field to convert a currency field to text so that it displays the correct number of decimal places when exported to a word document using WebMerge.
I don't have thousands separation anymore. Is there a workaround for this?
Many Thanks,
John. -
Hi John,
I use this to get the thousand separator (,):
Field.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
Rainer
rg@delos-consulting.com -
Hi James,
everytime you enter something in a calculation field, you use Javascript. Calculation fields are based on Javascript.
If you only add a token into a calculation field like
@AVG of some field
you can define the number of decimals in the feild settings (which rounds the result):
Rainer
-
Hello Guys & Podio,
My rounding problem is before,00 - I need to round the result up to nearest 5. I have used some of your java solutions before, and now I found 2 one at php.net and one on Stack Overflow, I can not get them to work.
But then again, I know nothing about java or php.I would appreciat any help, thanks
It says
float ceil ( float
$value
)
----
<?php
echo ceil(4.3); // 5
echo ceil(9.999); // 10
echo ceil(-3.14); // -3
?>
----
function round5(x) { return Math.ceil(x/5)*5; }
-------------------
Thanks for your help -
Hi Hans,
PHP and Java solutions don't help cause the Podio calculation field uses JavaScript (and yes, Java and JavaSript are completly different things).
If you want to round an integer to the nearest 5 (= round up or down)
var val = 22;
Math.round(val/5)*5Result: 20
If you want to round to the next 5 (= always round up)
var val = 22;
Math.ceil(val/5)*5Result 25
A function you only need if you've many number values in your calculation and if you want to avoid to enter the formula for each one
function round5(x) { return Math.ceil(x/5)*5; };
round5(numberA) + round5(numberB) + round5(numberC)Rainer
Please sign in to leave a comment.
Comments
13 comments