|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Is this a bug?Hi all
I tried : Dim test as Decimal = Cdec(Val("-20.0000")). This return 0. Also using Decimal.TryParse with the above string returns false. Surely this is not correct? Cheers Hello Harry,
I just tested it and it returned -20. Best regards, Martin On 18.06.2009 05:35, Harry wrote: Show quoteHide quote > Dim test as Decimal = Cdec(Val("-20.0000"))
Show quote
Hide quote
"Harry" <harryNoSpam@ffapaysmart.com.au> wrote in message Is that really the code that produces the zero? Perhaps your code has a news:ugGhWX87JHA.5828@TK2MSFTNGP04.phx.gbl... > Hi all > > I tried : > > Dim test as Decimal = Cdec(Val("-20.0000")). This return 0. > > Also using Decimal.TryParse with the above string returns false. > Surely this is not correct? > > Cheers > > charactor that does not print before the -20.0000. In such a case, you would get zero on converting, and false for tryparse. -- Mike What I see here in France :
Cdec(Val("-20.0000")) returns 20. This is what I expect as the Val function parse . as the decimal point. IMO it should always work. Decimal.TryParse returns false. This is also what I expect as . is not valid in my country... The result depends on your country... -- Patrice "Harry" <harryNoSpam@ffapaysmart.com.au> a écrit dans le message de groupe de discussion : ugGhWX87JHA.5***@TK2MSFTNGP04.phx.gbl...Show quoteHide quote > Hi all > > I tried : > > Dim test as Decimal = Cdec(Val("-20.0000")). This return 0. > > Also using Decimal.TryParse with the above string returns false. > Surely this is not correct? > > Cheers > > "Harry" <harryNoSpam@ffapaysmart.com.au> wrote in message Don't use Val() for something that the user enter, or in other than US news:ugGhWX87JHA.5828@TK2MSFTNGP04.phx.gbl... > Hi all > > I tried : > > Dim test as Decimal = Cdec(Val("-20.0000")). This return 0. > > Also using Decimal.TryParse with the above string returns false. > Surely this is not correct? format. Use CDec without Val, or TryParse. Here is an example: Dim test As Decimal = CDec(Val("-20.0000")) Console.WriteLine("Test = " & test) test = CDec(Val("-20.7000")) Console.WriteLine("Test = " & test) test = CDec(Val("-20,7000")) Console.WriteLine("Test = " & test) test = CDec("-20.7000") Console.WriteLine("Test = " & test) test = CDec("-20,7000") Console.WriteLine("Test = " & test) Output in VB 2008 when Control Panel is set to US/English: Test = -20 Test = -20.7 Test = -20 Test = -20.7000 Test = -207000
Need some help from VB Programmers...
How to hide base class member variable in derived class (w/o shadows)? Visual Basic is Dead! Blanking Monitor and Unblanking Monitor serialPort receive problem Application Icon language for databases Creating user friendly error messages for SqlExceptions SerialPort in vista QBasic 4.5 modules in VB.Net? |
|||||||||||||||||||||||