Android Question Specify thousands separator?

Discussion in 'Android Questions' started by Roger Daley, Dec 17, 2016.

  1. Roger Daley

    Roger Daley Well-Known Member Licensed User

    Hi All,

    I have been searching for a way for the user to specify/select their preferred separator in decimal numbers. IE Thousands separator can be comma-dot-space or none.

    This has been asked in the distant past but I see no real solution.

    Regards Roger
     
    Last edited: Dec 20, 2016
  2. DonManfred

    DonManfred Expert Licensed User

  3. Erel

    Erel Administrator Staff Member Licensed User

    Depends on AHLocale, Reflection and JavaObject libraries:
    Code:
    Sub Process_Globals
       
    Private nf As AHNumeric
    End Sub

    Sub Globals

    End Sub

    Sub Activity_Create(FirstTime As Boolean)
       
    If FirstTime Then
         nf = SetFormatChars(
    "~"":")
       
    End If
       
    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
     
  4. Roger Daley

    Roger Daley Well-Known Member Licensed User


    Thanks Erel,

    It looks like what I need. Perhaps we could add Numberformat3 to the wish list. Several dedicated options and auto-locale.

    Regards Roger
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice