Android Question xChart scientific number notation

Discussion in 'Android Questions' started by RB Smissaert, May 16, 2018.

  1. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    Noticed that if I have for example a value of 0.01 this will show in scientific notation when clicking the graph. This seems a bit too early to me as users may get confused with the scientific notation and showing
    0.01 is quite OK. To avoid this problem I added another xChart property, MaxDecimals.

    This was the code added, going from top to bottom in the xChart class:

    Code:
    #DesignerProperty: Key: MaxDecimals, DisplayName: Max decimals, FieldType: Int, DefaultValue: 5, Description: Sets the max number of allowed decimals needed to show a non-zero value before changing to scientific notation.

     
    Type ValuesData (Show As Boolean, TextFont As B4XFont, TextSize As Float, TextColor As Int, TextHeight As Int, Left As Int, Top As Int, Width As Int, Height As Int, MidPont As Int, rectRight As B4XRect, rectCursor As B4XRect, MaxDigits As Int, MaxDecimals As Int)

    Values.MaxDecimals = Props.Get(
    "MaxDecimals"'<<<< added

    '>>>> added this is useful as the fixed value of 2 seems too low
    'something like 0.01 then shows as scientific notation, which will confuse users
    'and is not really needed
    '-------------------------------------------------------------------------------
    Public Sub getMaxDecimals As Int
     
    Return Values.MaxDecimals
    End Sub

    Public Sub setMaxDecimals (iMaxDecimals As Int)
     Values.MaxDecimals = iMaxDecimals
    End Sub
    Then in In Sub NumberFormat3:

    Code:
    'If exp < MaxDigits And exp > -2 Then
     If exp < MaxDigits And exp > 0 - Values.MaxDecimals Then
      str = 
    NumberFormat2(Number, 1, MaxDigits - 1 - exp, 0False)
     
    Else
      mant = 
    Power(10, lng)
      str = strMinus & 
    NumberFormat2(mant, 1, MaxDigits - 10False)
      str = str & 
    "E" & exp
     
    End If
    [CODE]


    RBS
     
  2. klaus

    klaus Expert Licensed User

    I am on travel.
    I will look at it when I am back on monday.
     
  3. RB Smissaert

    RB Smissaert Well-Known Member Licensed User

    OK, have a nice journey or holiday.

    RBS
     
  4. klaus

    klaus Expert Licensed User

    I replaced it by this:
    Code:
    If exp < MaxDigits And exp > -5 Then
        str = 
    NumberFormat2(Number, 1, MaxDigits - 1 - exp, 0False)
    Else If exp <= -5 And exp > -7 Then
        str = 
    NumberFormat2(Number, 190False)
    Else
        mant = 
    Power(10, lng)
        str = strMinus & 
    NumberFormat2(mant, 1, MaxDigits - 10False)
        str = str & 
    "E" & exp
    End If
    Therfore
    0.000123456 is displayed 0.000123456
    0.0000123456 is displayed 0.000012346
    0.00000123456 is displayed 0.000001235
    0.000000123456 is displayed 1.23456E-7
     
    Last edited: May 22, 2018
    Erel and Johan Hormaza like this.
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