Forum


Calc Builder Support

Calc Builder support
Forums
No se permite escribir sin estar logado. Por favor, login

decimal points and calculation error 13.03.2013 15:35

Hello.

I built a form, and added the decimal points in php as the commas and dec points weren't rendered even though I added in preferences.

I do have joomla 1.5 version. My calculations do else work fine, but not the last one:

$kontrol=0.25;
$fejlreg=10;
$time=60;
$indtast=5;
$maaneder=12;
$faktor=1.2;
$timertot=1850;

$result_1=$num1*$kontrol*$maaneder*$num2;
$result_1=number_format($result_1,2,',','.');
$timer_1=$num1*$kontrol*$maaneder;

$result_2=(($num1*$fejlreg)/$time)*$num2*$maaneder;
$result_2=number_format($result_2,2,',','.');
$timer_2=(($num1*$fejlreg)/$time)*$maaneder;

$result_3=(($num1*$indtast)/$time)*$num2*$maaneder;
$result_3=number_format($result_3,2,',','.');
$timer_3=(($num1*$indtast)/$time)*$maaneder;

$ratio=(($num2*$num1*$timertot)/100);
$ratio=number_format($ratio,2,',','.');

$result=$result_1+$result_2+$result_3+$ratio;
$result=number_format($result,2,',','.');

Frontend result:

result_1 ok
result_2 ok
result_3 ok
ratio ok
result wrong

url: http://www.dynaway.com/roi

Anybody out there who can tell me what I did wrong?

Thank you in advance

Kind regards

Jeannine

Re: decimal points and calculation error 13.03.2013 15:54

Hello,

You´re trying to add $result_1 and $result_2 and so on to get $result. The problem is that $result_1 is a String, not a number. You should save $result_1 as number before applying number_format function and then use it.

Code looks like this:



...

$result_1=$num1*$kontrol*$maaneder*$num2;
$result_1_int=$result_1;
$result_1=number_format($result_1,2,',','.');

...

$result=$result_1_int+$result_2_int+$result_3_int+$ratio_int;
$result=number_format($result,2,',','.');



Hope this helps.
Moonsoft Team
www.moonsoft.es

Re: decimal points and calculation error 18.03.2013 09:24

Thank you so much for helping! It's still not working right, unfortunately.
shouldnt that as well define the variables as numbers: $result_1=number_format($result_1,2,',','.');?

I know that if you try the calculation with 200 employees and 135 wage you finally should retrieve following numbers:

Fejlratio:

(1,2 % af den årlige lønomkostning)
Omkostninger: 499.500,00 kr. pr. anno
-> should be: 600.000,00

TOTAL= 108.054,00
-> should be: 763.620,00

Re: decimal points and calculation error 19.03.2013 12:08

Hello,

Number format is not used to define variables as numbers, but to format them. So, you only have to perform all calculations without using number_format function and once all results are calculated execute number_format function as the last lines of your calculators.

Regards,
Moonsoft Team
www.moonsoft.es

Re: decimal points and calculation error 19.03.2013 14:36

Now I figured it out!

Thank you sooo much indeed

Cheers from Denmark to lovely Spain

Jeannine
Are you satisfied with our products/services/support?
Please help us to keep improving, add a review at  joomla extensions site and  magento connect
FaLang translation system by Faboba

Lo que nuestros clientes opinan de nosotros