Results 1 to 5 of 5

Thread: problem with decimal point ( , .)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Posts
    15

    Unhappy

    I use some strings in a formula.
    These strings can be "19.23" or "19,23".
    I need the numbers to use in my formula.
    I can use val() or Cdbl() but i have the problem
    val(19.23) -> 19,23
    val(19,23) -> 19
    Cdbl(19.23) -> 1923
    Cdbl(19,23) -> 19,23
    With a . i have to use val() and with a , i have to use
    Cdbl().
    Is there something that recognize both?

    Thanks

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    Do a bit of validation before the conversion:
    Code:
    Sub ToNumber(strValue As String) As Double
       If IsNumeric(strValue) Then
           strValue = Replace(strValue, ",", vbNullString)
           ToNumber = CDbl(strValue)
       Else
           ToNumber = 0
       End If
    End Sub
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Posts
    15
    Thanks for the reply but,with your program i lose the decimal point and i don't have to lose it, i want to keep it.
    Perhaps i can use Replace(strValue, ".", ",").

  4. #4
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    I think you are using a comma(,) as a decimal and I am using a period(.). Whatever you are using in your country as a decimal, then it MUST be retained.

    In the UK, the comma is used as a thousand separator (10,000.00) therefore can be omitted without any detrimental problems (10000.00)Ten Thousand. If I replace the period, then the number becomes (1000000) Million.

    Hope all is now OK

    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 1999
    Posts
    15
    I am from Belgium and we use , as decimal point.
    Sometimes it's a problem because on the keyboards
    numbersection it's a point so we use sometimes a point.
    So that's why i have different values
    (23.32 and 23,32)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width