Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datatype for 9 place decimal

Status
Not open for further replies.

ftsw

Technical User
Sep 17, 2002
9
0
0
US
Problem: inside php script need to multiply and find $a.
$x, $y, and $z are all datatype float(11,9) inside the carv table. I connect to database and select these values from carv table.
$x= 0.000182682
$y= 0.028863719
$z= 0.452137381

I do this multiplication inside my php script to find $a.
$a = $x * $y * $z
$a = 2.3840670190801E-006
This multiplication is obviously wrong.
Can you please help?
Sheldon
 
Wow! Those are some small numbers that needs to be multiplied... You do realize that the result would have 27 decimals, right? I'm not sure PHP can handle that, but have you checked the [tt]precision[/tt] variable in [tt]php.ini[/tt]?

//Daniel
 
I recommend that you use PHP's bc_match functions (
The following script:
Code:
<?php
bcscale (100);

$x= 0.000182682;
$y= 0.028863719;
$z= 0.452137381;

print bcmul(bcmul($x, $y), $z);
?>

Which produces as output:

0.000002384067019080092416398

which may be what you're looking for.

Want the best answers? Ask the best questions: TANSTAAFL!
 
Sheldon,
why you say the result is wrong? I've not verified, but it seems correct.
Gaetano
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top