|
Posted by Colin Fine on 10/07/06 19:04
mantrid wrote:
> I am trying to take an integer and divide it by 100 to give a decimal to
> store in my database. The field in my mysql database is set to decimal(4,2)
> My php is
> $price=number_format($price/100,2);
> Ive also tried
> $price=number_format($price,2)/100;
>
> but neither work it keeps rounding any value less than 100 to 1 whereas I
> want it to store the value to two DP
>
> eg
>
> 80 becomese 1 instead of 0.8
> 180 becomes 2 instead of 1.8
>
> does anyone know how to do this?
> Ian
>
>
AFAICS, number_format should deliver a string, which is what a
decimal(4,2) expects.
I wonder if you are failing to quote the string in your SQL? It would be
easier to tell if you posted the code.
On thing to try is to print out $price after the number_format, to check
whether the rounding happens then or later.
Colin
Navigation:
[Reply to this message]
|