-
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
-
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
:cool:
-
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, ".", ",").
-
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
:cool:
-
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)