Home All Groups Group Topic Archive Search About
Author
18 Oct 2006 3:06 PM
Altman
I am having a rounding problem all over the place and am struggling to
fix it.  My problem is that I have an unit price and a quantity.  When
I multiply them together they come out to 3.705.  I want to round this
to 2 decimals.  It always rounds to 3.70 though.  Even when I put
math.round(3.705,2) in the debug watch, I get 3.70.  How can I get this
to round correctly?  I know one option would probably be to add .00001
to the value before rounding, as I am sure this is floating point
issue, but that might cause a problem in the future with other data.

Author
18 Oct 2006 3:20 PM
rowe_newsgroups
Math.Round(3.705, 2, MidpointRounding.AwayFromZero)

Won't that work?

Thanks,

Seth Rowe


Altman wrote:
Show quoteHide quote
> I am having a rounding problem all over the place and am struggling to
> fix it.  My problem is that I have an unit price and a quantity.  When
> I multiply them together they come out to 3.705.  I want to round this
> to 2 decimals.  It always rounds to 3.70 though.  Even when I put
> math.round(3.705,2) in the debug watch, I get 3.70.  How can I get this
> to round correctly?  I know one option would probably be to add .00001
> to the value before rounding, as I am sure this is floating point
> issue, but that might cause a problem in the future with other data.
Author
18 Oct 2006 7:23 PM
Altman
I was unaware of the third parameter in the round function.  It seems
to me that "AwayFromZero" should be the default setting but it
obviously is not that way.

rowe_newsgroups wrote:
Show quoteHide quote
> Math.Round(3.705, 2, MidpointRounding.AwayFromZero)
>
> Won't that work?
>
> Thanks,
>
> Seth Rowe
>
>
> Altman wrote:
> > I am having a rounding problem all over the place and am struggling to
> > fix it.  My problem is that I have an unit price and a quantity.  When
> > I multiply them together they come out to 3.705.  I want to round this
> > to 2 decimals.  It always rounds to 3.70 though.  Even when I put
> > math.round(3.705,2) in the debug watch, I get 3.70.  How can I get this
> > to round correctly?  I know one option would probably be to add .00001
> > to the value before rounding, as I am sure this is floating point
> > issue, but that might cause a problem in the future with other data.
Author
18 Oct 2006 3:25 PM
Miro
Take a look at this link i think it will help you.

http://www.developerfusion.co.uk/show/4252/


Miro


Show quoteHide quote
"Altman" <balt***@easy-automation.com> wrote in message
news:1161183990.987333.237570@m7g2000cwm.googlegroups.com...
>I am having a rounding problem all over the place and am struggling to
> fix it.  My problem is that I have an unit price and a quantity.  When
> I multiply them together they come out to 3.705.  I want to round this
> to 2 decimals.  It always rounds to 3.70 though.  Even when I put
> math.round(3.705,2) in the debug watch, I get 3.70.  How can I get this
> to round correctly?  I know one option would probably be to add .00001
> to the value before rounding, as I am sure this is floating point
> issue, but that might cause a problem in the future with other data.
>
Author
18 Oct 2006 4:31 PM
Cor Ligthert [MVP]
Altman,

Maybe not so nice as program but it is very easy to do

dim a as double = 3.705
a + .005
dim b as double = Cdbl(a.ToString("d"))

I am not always sure from that "d" but if that is wrong have than a look at
the overloaded ToString for the correct patern.

(In net is used the ISO banking rounding, I never heard who it was using
outside that world and they use if definitley not here for their clients).

I hope this helps,

Cor

Show quoteHide quote
"Altman" <balt***@easy-automation.com> schreef in bericht
news:1161183990.987333.237570@m7g2000cwm.googlegroups.com...
>I am having a rounding problem all over the place and am struggling to
> fix it.  My problem is that I have an unit price and a quantity.  When
> I multiply them together they come out to 3.705.  I want to round this
> to 2 decimals.  It always rounds to 3.70 though.  Even when I put
> math.round(3.705,2) in the debug watch, I get 3.70.  How can I get this
> to round correctly?  I know one option would probably be to add .00001
> to the value before rounding, as I am sure this is floating point
> issue, but that might cause a problem in the future with other data.
>