• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

PHP Rounding

sarcastic6

Limp Gawd
Joined
Jun 11, 2001
Messages
223
I'm trying to figure out why this isn't working.

Consider the following code:
PHP:
$salesTaxAmount = $subtotal * ($salesTaxPercent / 100);
$salesTax = round($salesTaxAmount , 2);
echo "Sales tax amount (calculated) is: " . $salesTaxAmount . ", ";
echo "sales tax (rounded) is: " . $salesTax . ", ";
echo "\$salesTaxAmount is a " . gettype($salesTaxAmount) . ", ";
echo "\$salesTax is a " . gettype($salesTax);

It outputs this:
Code:
Sales tax amount (calculated) is: 2.325, 
sales tax (rounded) is: 2.32, 
$salesTaxAmount is a double, 
$salesTax is a double

And yet if I do a round(2.325, 2) manually, I get the CORRECT value, 2.33. What is going on?
 
Code:
subtotal (calculated) is: 38.75, 
salesTaxPercent (from DB) is: 6, 
sales tax amount (calculated) is: 2.325, 
sales tax (rounded) is: 2.32, 
$salesTaxAmount is a double, 
$salesTaxAmount is a double
 
Aw, that's not fair. 30 minutes ago, all user comments were unavailable! :) Ah well, either way, got it working now, thank you.
 
sarcastic6 said:
Aw, that's not fair. 30 minutes ago, all user comments were unavailable! :) Ah well, either way, got it working now, thank you.

user notes are still down :/

Had to go to a mirror for that.

--KK
 
Ah, I see now. I had thought they were completely unavailable. I wish I had learned that trick a few days ago! Strange, I wonder why they didn't mention that in the news post...
 
Back
Top