ZaneDeFazio
ZaneDeFazio

Reputation: 509

Should be basic arithmetic

For some reason this isn't storing the variable correctly giving me a value of "0" after the equation.

if ($power_weight  == '') {
    $power_weight = NULL;
}
else {
    $power_weight = $power_weight / 1.01387 * 2.20462262;
}
echo $power_weight;

When a similar equation works fine

if ($zero_sixty == '') {
    $zero_sixty = NULL;
}
else {
    $zero_sixty = $zero_sixty * 60 / 62;
}
echo $zero_sixty;

Upvotes: 1

Views: 76

Answers (2)

ajreal
ajreal

Reputation: 47331

This is caused by floating point number with limited precision

Highly possible reason is using type hinting like (int) $power_weight

Upvotes: 1

Alex Weinstein
Alex Weinstein

Reputation: 9891

What's the value of power_weight before this snippet? Is it a string or a float? I'd encourage you to parse it by doing floatval() on it.

Upvotes: 1

Related Questions