I'm facing a strange issue where Cint and Cdbl are not returning expected output on Swedish keyboard. They work fine on English keyboard.
Cint("6.0") # Output: 60
Cdbl("70.8") # Output: 708
For some reason, both the functions are removing the decimal from string.
In VBA use Val
, which always assume dot as decimal separator.
In VBScript, I use to solve this question using:
CDbl(Replace(number_in_string, ".", Mid(1.3, 2, 1)))
This way numeric 1.3 is converted into a localized string and decimal separator extracted from 2rd character. Then, dot in supplied string is replaced by decimal separator extracted.
Possible issues:
Thousand separators! If your number use thousand separators that are the same of your system decimal separator, convertion will get corrupt! Example: "1,234.56"
will become "1,234,56"
! Workaround:
CDbl(Replace(Replace(number_in_string, ",", ""), ".", Mid(1.3, 2, 1))) 'Remove comma thousand separator
Number formating: assuming 1.3
will become a string where decimal separator is in 2nd character is not acquired for sure!