CalcBuilder Forum

decimal points and calculation error

User moon_943 2013-03-13 15:35:09

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

Moonsoft support 2013-03-13 15:54:02

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.

User moon_943 2013-03-18 09:24:18

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

Moonsoft support 2013-03-19 12:08:14

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,

User moon_943 2013-03-19 14:36:52

Now I figured it out!

Thank you sooo much indeed :-)

Cheers from Denmark to lovely Spain

Jeannine

...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!
...
Support/development

Perfect for small code changes or to correct any bug at your site

Buy now!