|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Is this a bug: 2.2 - 0.4 = 1.8 but 1.2 - 0.4 = 0.8000001 ?Dim a, b As Single a = 2.2 b = 0.4 Response.Write(a - b) This gives: 1,8 (rendered according my regional settings) But this gives: 0,8000001 (rendered according my regional settings): Dim a, b As Single a = 1.2 b = 0.4 Response.Write(a - b) Any explantion for this, and how to solve this?? ( i rounded on two digits) Thanks Dave Dave,
Try: | Dim a, b As Decimal Is given as that is the approximate value that a Single can hold. A Single | a = 2.2D | b = 0.4D | Response.Write(a - b) | But this gives: 0,8000001 (rendered according my regional settings): holds base 2 floating point numbers, some (most) base 10 floating point numbers cannot be exactly represented For details see: http://www.yoda.arachsys.com/csharp/floatingpoint.html http://www.yoda.arachsys.com/csharp/decimal.html NOTE: The D in 2.2D indicates it is a Decimal literal as opposed to 2.2 which is a Double literal, as opposed to 2.2F which is a Single literal. -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Dave" <sd***@fgn.qc> wrote in message news:OdejlHCqGHA.4684@TK2MSFTNGP05.phx.gbl... | Hi, | | Dim a, b As Single | a = 2.2 | b = 0.4 | Response.Write(a - b) | | This gives: 1,8 (rendered according my regional settings) | | | But this gives: 0,8000001 (rendered according my regional settings): | Dim a, b As Single | a = 1.2 | b = 0.4 | Response.Write(a - b) | | | Any explantion for this, and how to solve this?? ( i rounded on two digits) | Thanks | Dave | | Thanks,
suppose i use variables a and b which are defined as decimals and gets their values from anywhere else. How can i put the "D" after the variable : c=a-b D Show quoteHide quote "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> schreef in bericht news:ehgZCVCqGHA.2452@TK2MSFTNGP03.phx.gbl... > Dave, > Try: > > | Dim a, b As Decimal > | a = 2.2D > | b = 0.4D > | Response.Write(a - b) > > | But this gives: 0,8000001 (rendered according my regional settings): > Is given as that is the approximate value that a Single can hold. A Single > holds base 2 floating point numbers, some (most) base 10 floating point > numbers cannot be exactly represented > > For details see: > > http://www.yoda.arachsys.com/csharp/floatingpoint.html > > http://www.yoda.arachsys.com/csharp/decimal.html > > > NOTE: The D in 2.2D indicates it is a Decimal literal as opposed to 2.2 > which is a Double literal, as opposed to 2.2F which is a Single literal. > > > -- > Hope this helps > Jay B. Harlow [MVP - Outlook] > .NET Application Architect, Enthusiast, & Evangelist > T.S. Bradley - http://www.tsbradley.net > > > "Dave" <sd***@fgn.qc> wrote in message > news:OdejlHCqGHA.4684@TK2MSFTNGP05.phx.gbl... > | Hi, > | > | Dim a, b As Single > | a = 2.2 > | b = 0.4 > | Response.Write(a - b) > | > | This gives: 1,8 (rendered according my regional settings) > | > | > | But this gives: 0,8000001 (rendered according my regional settings): > | Dim a, b As Single > | a = 1.2 > | b = 0.4 > | Response.Write(a - b) > | > | > | Any explantion for this, and how to solve this?? ( i rounded on two > digits) > | Thanks > | Dave > | > | > > | suppose i use variables a and b which are defined as decimals and gets If you define the variable as Decimal, the variable will hold a Decimal.their | values from anywhere else. | c=a-b D a is a variable of type Decimal, it will return a Decimal value, literals are not involved here, so you don't need the "literal type character D". The D is part of a Literal (constant if you will) value. 2.2 is a literal a is a variable b is a variable c is a variable 2.2 is a Double literal 2.2D is a Decimal literal 2.2F is a Single literal (the F stands for Float). -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Dave" <sd***@fgn.qc> wrote in message news:uqcEViCqGHA.2452@TK2MSFTNGP03.phx.gbl... | Thanks, | | suppose i use variables a and b which are defined as decimals and gets their | values from anywhere else. | How can i put the "D" after the variable : | c=a-b D | | | | | "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> schreef in | bericht news:ehgZCVCqGHA.2452@TK2MSFTNGP03.phx.gbl... | > Dave, | > Try: | > | > | Dim a, b As Decimal | > | a = 2.2D | > | b = 0.4D | > | Response.Write(a - b) | > | > | But this gives: 0,8000001 (rendered according my regional settings): | > Is given as that is the approximate value that a Single can hold. A Single | > holds base 2 floating point numbers, some (most) base 10 floating point | > numbers cannot be exactly represented | > | > For details see: | > | > http://www.yoda.arachsys.com/csharp/floatingpoint.html | > | > http://www.yoda.arachsys.com/csharp/decimal.html | > | > | > NOTE: The D in 2.2D indicates it is a Decimal literal as opposed to 2.2 | > which is a Double literal, as opposed to 2.2F which is a Single literal. | > | > | > -- | > Hope this helps | > Jay B. Harlow [MVP - Outlook] | > .NET Application Architect, Enthusiast, & Evangelist | > T.S. Bradley - http://www.tsbradley.net | > | > | > "Dave" <sd***@fgn.qc> wrote in message | > news:OdejlHCqGHA.4684@TK2MSFTNGP05.phx.gbl... | > | Hi, | > | | > | Dim a, b As Single | > | a = 2.2 | > | b = 0.4 | > | Response.Write(a - b) | > | | > | This gives: 1,8 (rendered according my regional settings) | > | | > | | > | But this gives: 0,8000001 (rendered according my regional settings): | > | Dim a, b As Single | > | a = 1.2 | > | b = 0.4 | > | Response.Write(a - b) | > | | > | | > | Any explantion for this, and how to solve this?? ( i rounded on two | > digits) | > | Thanks | > | Dave | > | | > | | > | > | | Thanks again
Show quoteHide quote "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> schreef in bericht news:%23noZQPDqGHA.3288@TK2MSFTNGP03.phx.gbl... >| suppose i use variables a and b which are defined as decimals and gets > their > | values from anywhere else. > If you define the variable as Decimal, the variable will hold a Decimal. > > | c=a-b D > > a is a variable of type Decimal, it will return a Decimal value, > literals are not involved here, so you don't need the "literal type > character D". > > The D is part of a Literal (constant if you will) value. > > 2.2 is a literal > > a is a variable > > b is a variable > > c is a variable > > 2.2 is a Double literal > > 2.2D is a Decimal literal > > 2.2F is a Single literal (the F stands for Float). > > > -- > Hope this helps > Jay B. Harlow [MVP - Outlook] > .NET Application Architect, Enthusiast, & Evangelist > T.S. Bradley - http://www.tsbradley.net > > > "Dave" <sd***@fgn.qc> wrote in message > news:uqcEViCqGHA.2452@TK2MSFTNGP03.phx.gbl... > | Thanks, > | > | suppose i use variables a and b which are defined as decimals and gets > their > | values from anywhere else. > | How can i put the "D" after the variable : > | c=a-b D > | > | > | > | > | "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> schreef > in > | bericht news:ehgZCVCqGHA.2452@TK2MSFTNGP03.phx.gbl... > | > Dave, > | > Try: > | > > | > | Dim a, b As Decimal > | > | a = 2.2D > | > | b = 0.4D > | > | Response.Write(a - b) > | > > | > | But this gives: 0,8000001 (rendered according my regional settings): > | > Is given as that is the approximate value that a Single can hold. A > Single > | > holds base 2 floating point numbers, some (most) base 10 floating > point > | > numbers cannot be exactly represented > | > > | > For details see: > | > > | > http://www.yoda.arachsys.com/csharp/floatingpoint.html > | > > | > http://www.yoda.arachsys.com/csharp/decimal.html > | > > | > > | > NOTE: The D in 2.2D indicates it is a Decimal literal as opposed to > 2.2 > | > which is a Double literal, as opposed to 2.2F which is a Single > literal. > | > > | > > | > -- > | > Hope this helps > | > Jay B. Harlow [MVP - Outlook] > | > .NET Application Architect, Enthusiast, & Evangelist > | > T.S. Bradley - http://www.tsbradley.net > | > > | > > | > "Dave" <sd***@fgn.qc> wrote in message > | > news:OdejlHCqGHA.4684@TK2MSFTNGP05.phx.gbl... > | > | Hi, > | > | > | > | Dim a, b As Single > | > | a = 2.2 > | > | b = 0.4 > | > | Response.Write(a - b) > | > | > | > | This gives: 1,8 (rendered according my regional settings) > | > | > | > | > | > | But this gives: 0,8000001 (rendered according my regional settings): > | > | Dim a, b As Single > | > | a = 1.2 > | > | b = 0.4 > | > | Response.Write(a - b) > | > | > | > | > | > | Any explantion for this, and how to solve this?? ( i rounded on two > | > digits) > | > | Thanks > | > | Dave > | > | > | > | > | > > | > > | > | > >
Resume next in VB.NET ?
C.NET VS VB6 Using A Bound Dataset to insert new Can I make my Form visible during a debug session? Database Connection Problem. Please Help ddl selectedindexchanged not firing on first item - I'm using a dataset to populate the ddl Seeking Design Advice object reference not set to an instance of an object error What's wrong with the combobox in grid webbrowser document text not adding text |
|||||||||||||||||||||||