round function issue

round function issue

am 17.10.2007 16:33:06 von davidkruger

Hi Everyone,

I am having a little problem that I am hoping someone can help me out
with. In one of my scripts, I am working with some dollar values, and
using round to change the result calculated values into a dollar value
with cents etc...so I should be getting $200.43 instead of $200.42987
etc.

The command I am using is:

$total_revenue = round(($renew+$inc_new+$national_rec+$chargeback),2);

This had been working previously on the old server, but a few days
ago, I transferred everything to a new system, and now it is as though
the round command is ignoring the 2 for decimal places and instead
rounding up to the next dollar value.

I am not 100% sure yet if it is caused by the round command itself, or
when I perform some math on the values used in the round command yet,
the values are taken from a string, and before any calculations are
made with the values, has 0 added to the value from the string, I
think this is supposed to change it to a number instead of a
string...so I am wondering if adding the 0 is causing the problem
perhaps?

Thanks,
David

Re: round function issue

am 17.10.2007 16:54:03 von Hans-Peter Sauer




<1192631586.455946.270240@v29g2000prd.googlegroups.com>

> I am having a little problem that I am hoping someone can help me out
> with. In one of my scripts, I am working with some dollar values, and
> using round to change the result calculated values into a dollar value
> with cents etc...so I should be getting $200.43 instead of $200.42987
> etc.
>
> The command I am using is:
>
> $total_revenue = round(($renew+$inc_new+$national_rec+$chargeback),2);
>
> This had been working previously on the old server, but a few days
> ago, I transferred everything to a new system, and now it is as though
> the round command is ignoring the 2 for decimal places and instead
> rounding up to the next dollar value.
>

Never used round() but www.php.net/manual/en/function.number-format.php
might be worth a look .


--
www.vhit.co.uk
www.jpgimage.co.uk
www.phpwhois.co.uk
www.cannabiswindow.co.uk

Re: round function issue

am 17.10.2007 16:57:28 von davidkruger

On Oct 17, 9:54 am, Krustov wrote:
>
>
>
> <1192631586.455946.270...@v29g2000prd.googlegroups.com>
>
> > I am having a little problem that I am hoping someone can help me out
> > with. In one of my scripts, I am working with some dollar values, and
> > using round to change the result calculated values into a dollar value
> > with cents etc...so I should be getting $200.43 instead of $200.42987
> > etc.
>
> > The command I am using is:
>
> > $total_revenue = round(($renew+$inc_new+$national_rec+$chargeback),2);
>
> > This had been working previously on the old server, but a few days
> > ago, I transferred everything to a new system, and now it is as though
> > the round command is ignoring the 2 for decimal places and instead
> > rounding up to the next dollar value.
>
> Never used round() butwww.php.net/manual/en/function.number-format.php
> might be worth a look .
>
> --www.vhit.co.ukwww.jpgimage.co.ukwww.phpwhois.co.ukwww.cann abiswindow.co.uk

Thanks, I did find that it is not actually caused by the round
function, but it seems a mysql problem, so will need to check it out
over there.