iOS Question Decimal seperator according to region and language

MList

Member
Licensed User
B4X:
Public Sub AusgabeWert(language As String, region As String, einheit As String ,number As Double) As String
    Dim jo As JavaObject
    jo = jo.InitializeNewInstance("java.util.Locale.Builder", Null)
    Dim locale As JavaObject = jo.RunMethodJO("setLanguage", Array As Object(language)).RunMethodJO("setRegion", Array As Object(region)).RunMethod("build", Null)
    Dim numberFormatter As JavaObject = jo.InitializeStatic("java.text.NumberFormat").RunMethod("getNumberInstance", Array As Object(locale))
    Dim retVal As String = numberFormatter.RunMethod("format", Array As Object(number))
    
    Return retVal
end sub

Have to transfer this B4A code...
How can i do that in IOS ?
Thanks for help...
 

emexes

Expert
Licensed User
How can i do that in IOS ?
If the user types in similar information, then you could take your cue from that eg before converting user input number from string to numeric, check to see if they've used a dot or a comma, and set the decimal separator character accordingly.

I've done similar stuff with units and date/time formats, eg if user enters "27cm" then changes to metric, or if enters "11in" (or "11 inch" or "11 inches") then changes to imperial.

Also super-popular with users was ability to type dates such as "yesterday", "today", "tomorrow", "next monday", "last tuesday", etc although there was occasional disagreement about whether eg if today is Tuesday, then is next Wednesday the following day, or the Wednesday of next week? 🤔
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim formatter As B4XFormatter
formatter.Initialize
formatter.GetDefaultFormat.DecimalPoint = GetDecimalSeparator
Log(formatter.Format(123.54))

Sub GetDecimalSeparator As String
    Dim locale As NativeObject
    Return locale.Initialize("NSLocale").RunMethod("currentLocale", Null).GetField("decimalSeparator").AsString
End Sub
 
Upvote 0
Top