B4J Question Specify thousands and decimal separator?

hibrid0

Active Member
Licensed User
Longtime User
Hi guys I want to change the decimal separator.
I see something for B4A but not work for B4J.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use the same code as in B4A: https://www.b4x.com/android/forum/threads/specify-thousands-separator.74270/#post-471610

B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private nf As AHNumeric
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   nf = SetFormatChars("~", ":")
   Log(nf.Format(1000000.3434))
End Sub

Sub SetFormatChars(Grouping As Char, DecimalSeparator As Char) As AHNumeric
   Dim loc As AHLocale
   loc.InitializeUS
   Dim jloc As JavaObject = loc
   jloc = jloc.GetField("myLocale")
   Dim nfs As AHNumeric
   nfs.InitializeNumber2(loc)
   Dim r As Reflector
   r.Target = nfs
   Dim dfs As JavaObject
   dfs.InitializeNewInstance("java.text.DecimalFormatSymbols", Array(jloc))
   dfs.RunMethod("setGroupingSeparator", Array(Grouping))
   dfs.RunMethod("setDecimalSeparator", Array(DecimalSeparator))
   Dim jo As JavaObject = r.GetField("mNumberFormat")
   jo.RunMethod("setDecimalFormatSymbols", Array(dfs))
   Return nfs
End Sub

It depends on AHLocale (B4A library), JavaObject and jReflection.
 
Upvote 0
Top