decimal serious problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Agnes

    #1

    decimal serious problem

    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_cha nged.
    .....
    e.row("invamt") = e.row("unitpric e") * e.row("noofunit ")
    *E.row("exchang erate")

    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.ro w("unitprice" ) *
    e.row("noofunit ") *E.row("exchang erate") ,2)
    Me.InvAmt.text = Math.round(e.ro w("unitprice" ) *
    e.row("noofunit ") *E.row("exchang erate") ,2)
    Debugger again, it sometimes return 4.87 , but sometimes return 4.86.
    I don't know what's wrong, please help.







  • Cor Ligthert [MVP]

    #2
    Re: decimal serious problem

    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/lib...nd(VS.80).aspx

    I hope this helps,

    Cor


    "Agnes" <agnes@dynamict ech.com.hk> schreef in bericht
    news:OEjBQlsWGH A.1220@TK2MSFTN GP02.phx.gbl...[color=blue]
    > 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_cha nged.
    > ....
    > e.row("invamt") = e.row("unitpric e") * e.row("noofunit ")
    > *E.row("exchang erate")
    >
    > 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.ro w("unitprice" ) *
    > e.row("noofunit ") *E.row("exchang erate") ,2)
    > Me.InvAmt.text = Math.round(e.ro w("unitprice" ) *
    > e.row("noofunit ") *E.row("exchang erate") ,2)
    > Debugger again, it sometimes return 4.87 , but sometimes return 4.86.
    > I don't know what's wrong, please help.
    >
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • Dennis

      #3
      RE: decimal serious problem

      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


      "Agnes" wrote:
      [color=blue]
      > 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_cha nged.
      > .....
      > e.row("invamt") = e.row("unitpric e") * e.row("noofunit ")
      > *E.row("exchang erate")
      >
      > 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.ro w("unitprice" ) *
      > e.row("noofunit ") *E.row("exchang erate") ,2)
      > Me.InvAmt.text = Math.round(e.ro w("unitprice" ) *
      > e.row("noofunit ") *E.row("exchang erate") ,2)
      > Debugger again, it sometimes return 4.87 , but sometimes return 4.86.
      > I don't know what's wrong, please help.
      >
      >
      >
      >
      >
      >
      >
      >[/color]

      Comment

      Working...