Determine decimal separator (1 Viewer)

spikepl

Eledittingent Beliped
Local time
Tomorrow, 00:50
Joined
Nov 3, 2010
Messages
6,142
I need to determine what is the decimal separator on the user machine. I know how to do it in a complicated way. But how to do it simply? (the problem is that data always comes as text, formatted with "," as decimal separator, but this has to be read on different machines, so the output of, say Cdbl will differ, and that data is not suitable for Val)

(There is some APi that allows extraction of locale settings, but I was wondering if some simpler built-in property/method exists? In Excel there seems to be a property Application.DecimalSeparator. I could also run a small test, grab a decimal number stored in a string, try to read it using Cdbl and see what comes out )
 
Last edited:
Idea:

1. Divide 22 by 7 (for example)
2. Search within the result to see what decimal separator is used.
 
Thanks . I have plenty of workarounds. Was just wondering whether there is some property somewhere that would allow me to get the value as simply as in Excel.
 
Last edited:
Cint("0,1") yields 0 if "," is set as decimal separator
Cint("0.1") yields 0 if "." is set as decimal separator

So
Code:
Dim  IsMySeparatorAComma as Boolean
Dim  IsMySeparatorADot as Boolean

IsMySeparatorAComma = Cint("0,1")=0 ' True if "," is separator
IsMySeparatorADot = Cint("0.1")=0   ' True if "." is separator
Some other useful tidbits:

  • Val relies on "." as decimal separator, whereas the other from-string conversion functions (C.....) are influenced by locale settings
  • When writing SQL, and needing to input decimal numbers in the SQL string, the function Str creates a text from number, using "." as separator in the text irrespective of locale settings, so it's smart to internationalize the app like that. Val is then the reciprocal function.
 
Last edited:
I need to determine what is the decimal separator on the user machine. I know how to do it in a complicated way. But how to do it simply?

Nowadays, I came across similar problem and solved the situation with the following function:
Code:
Public Function OnluqYoxla(Yoxlanilan As String) As Variant

'// Ibrahim NOHBALAYEV terefinden tertib olunub.
'// Bu funksiya [1.75 ve ya 98,73] kimi kesr ededlerin onluq ayiraci simvolunu yoxlayir
'// ve Ememliyyat Sisteminin simvolu ile deyisir. Muqayise ucun eded - metn kimi yoxlanilir.
'// Yoxlanilacaq ededin yerine funkiyaya parametr olaraq qeyri-eded gonderilerse funksiya
'// hemin parametre beraber olacaq.

Dim Simv As String
Dim SimvA As String
Dim Metn As String

On Error GoTo ErrOnluqYoxla
Simv = Mid(1 / 2, 2, 1)
    If IsNull(Yoxlanilan) Or (Yoxlanilan = "") Then
        OnluqYoxla = 0
        Exit Function
    Else
        If InStr(1, Yoxlanilan, ",", vbTextCompare) <= 1 Then
            SimvA = "."
        Else
            SimvA = ","
        End If
        Metn = Replace(Yoxlanilan, SimvA, Simv)
        If IsNumeric(Metn) Then
            OnluqYoxla = CDbl(Metn)
        Else
            If IsDate(Metn) Then
                OnluqYoxla = CDate(Metn)
            Else
                OnluqYoxla = Metn
            End If
        End If
        Exit Function
    End If

ErrOnluqYoxla:
    OnluqYoxla = "SEHV: " & Err.Description
    Resume Next
End Function
Where "Yoxlanilan" is the decimal number that we want to control for a decimal symbol (but function compares it as String, then converts to Double).
Hope that this will be helpfull.
 
Last edited:
Thanks . I have plenty of workarounds. Was just wondering whether there is some property somewhere that would allow me to get the value as simply as in Excel.

As I found nowadays, there exists a simple function in Excel VBA for determining Date Separator, Decimal Separator, etc:

Code:
application.International(xldateseparator)
Code:
application.International(xldecimalseparator)
Wish a good day to all
 

Users who are viewing this thread

Back
Top Bottom