By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,175 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,175 IT Pros & Developers. It's quick & easy.

Rounding issue

P: n/a
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.

Oct 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
Oct 18 '06 #2

P: n/a
Take a look at this link i think it will help you.

http://www.developerfusion.co.uk/show/4252/
Miro
"Altman" <ba*****@easy-automation.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.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.

Oct 18 '06 #3

P: n/a
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

"Altman" <ba*****@easy-automation.comschreef in bericht
news:11**********************@m7g2000cwm.googlegro ups.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.

Oct 18 '06 #4

P: n/a
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:
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.
Oct 18 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.