Android Question xChart scientific number notation

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:

B4X:
#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:

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


RBS
 

klaus

Expert
Licensed User
I replaced it by this:
B4X:
If exp < MaxDigits And exp > -5 Then
    str = NumberFormat2(Number, 1, MaxDigits - 1 - exp, 0, False)
Else If exp <= -5 And exp > -7 Then
    str = NumberFormat2(Number, 1, 9, 0, False)
Else
    mant = Power(10, lng)
    str = strMinus & NumberFormat2(mant, 1, MaxDigits - 1, 0, False)
    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:
Top