Home All Groups Group Topic Archive Search About

decimal serious problem

Author
8 Apr 2006 5:00 AM
Agnes
myInvtable got a field named "invamt" which is decimail (9,2) ,

user will input the unitprice, noof unit in the table, and I will calculate
the amount.
in myInvDeatil_changed.
.....
    e.row("invamt") = e.row("unitprice") * e.row("noofunit")
*E.row("exchangerate")

When I use debugger to check, I found that e.row("invamt") = 4.875D  <--- 
Why not 4.86 ????
Then,
    I try .. e.row("invamt") = Math.round(e.row("unitprice") *
e.row("noofunit") *E.row("exchangerate") ,2)
              Me.InvAmt.text =   Math.round(e.row("unitprice") *
e.row("noofunit") *E.row("exchangerate") ,2)
Debugger again, it sometimes return 4.87 , but sometimes return 4.86.
I don't know what's wrong, please help.

Author
8 Apr 2006 7:20 AM
Cor Ligthert [MVP]
Agnes,

You are so long using this newsgroup. Your question has been often asked and
the answer is forever,  Net 1.x uses standard Banker's Rounding.

In version 2.0 you can now use as well rounding as it is mostly done in the
world.

http://msdn2.microsoft.com/en-us/library/system.decimal.round(VS.80).aspx

I hope this helps,

Cor


Show quoteHide quote
"Agnes" <ag***@dynamictech.com.hk> schreef in bericht
news:OEjBQlsWGHA.1220@TK2MSFTNGP02.phx.gbl...
> myInvtable got a field named "invamt" which is decimail (9,2) ,
>
> user will input the unitprice, noof unit in the table, and I will
> calculate the amount.
> in myInvDeatil_changed.
> ....
>    e.row("invamt") = e.row("unitprice") * e.row("noofunit")
> *E.row("exchangerate")
>
> When I use debugger to check, I found that e.row("invamt") = 4.875D  <--- 
> Why not 4.86 ????
> Then,
>    I try .. e.row("invamt") = Math.round(e.row("unitprice") *
> e.row("noofunit") *E.row("exchangerate") ,2)
>              Me.InvAmt.text =   Math.round(e.row("unitprice") *
> e.row("noofunit") *E.row("exchangerate") ,2)
> Debugger again, it sometimes return 4.87 , but sometimes return 4.86.
> I don't know what's wrong, please help.
>
>
>
>
>
>
>
Author
10 Apr 2006 1:27 PM
Dennis
Probably doesn't help but when I need to retain the exact decimal value, say
in a database, I save it as a string then convert it to decimal when I need
to use it.
--
Dennis in Houston


Show quoteHide quote
"Agnes" wrote:

> myInvtable got a field named "invamt" which is decimail (9,2) ,
>
> user will input the unitprice, noof unit in the table, and I will calculate
> the amount.
> in myInvDeatil_changed.
> .....
>     e.row("invamt") = e.row("unitprice") * e.row("noofunit")
> *E.row("exchangerate")
>
> When I use debugger to check, I found that e.row("invamt") = 4.875D  <--- 
> Why not 4.86 ????
> Then,
>     I try .. e.row("invamt") = Math.round(e.row("unitprice") *
> e.row("noofunit") *E.row("exchangerate") ,2)
>               Me.InvAmt.text =   Math.round(e.row("unitprice") *
> e.row("noofunit") *E.row("exchangerate") ,2)
> Debugger again, it sometimes return 4.87 , but sometimes return 4.86.
> I don't know what's wrong, please help.
>
>
>
>
>
>
>
>