In the process of converting from B4A to B4X.
As I understand it it is best to avoid using NumberFormat2.
No I need to show the average of a range of integer numbers and don't want to show scientific notation eg: Avg: 1.60018275E7.
I can do this fine with NumberFormat2, but not sure how to do it with B4XFormatter.
This is code to get the average value of a group and count map:
Any suggestions how to avoid the scientific notation in B4X?
RBS
As I understand it it is best to avoid using NumberFormat2.
No I need to show the average of a range of integer numbers and don't want to show scientific notation eg: Avg: 1.60018275E7.
I can do this fine with NumberFormat2, but not sure how to do it with B4XFormatter.
This is code to get the average value of a group and count map:
B4X:
Sub GetAvgOfGroupAndCountMap(oMap As Map, strDataType As String) As Double 'ignore
Dim lItems As Long
Dim Formatter As B4XFormatter 'use this rather than NumberFormat2 to make it B4X compatible
Formatter.Initialize
Dim DefaultFormat As B4XFormatData = Formatter.GetDefaultFormat
DefaultFormat.MaximumFractions = Enums.iAvgRoundingGroupAndCount
DefaultFormat.MinimumFractions = 0
DefaultFormat.MinimumIntegers = 0
DefaultFormat.DecimalPoint = "."
DefaultFormat.GroupingCharacter = ""
Select Case strDataType
Case "I", "L"
Dim lSum As Long
For Each oKey As Object In oMap.Keys
lSum = lSum + CLng(oKey) * CLng(oMap.Get(oKey))
lItems = lItems + CLng(oMap.Get(oKey))
Next
Log("lSum: " & lSum)
Log("lItems: " & lItems)
Log("NumberFormat2(" & lSum & "/" & lItems & ", 0, 1, 0, False): " & NumberFormat2(lSum/ lItems, 0, 1, 0, False))
Return Formatter.Format(lSum / lItems) 'show scientific format
Case "R"
Dim dSum As Double
For Each oKey As Object In oMap.Keys
dSum = dSum + CDbl(oKey) * CLng(oMap.Get(oKey))
lItems = lItems + CLng(oMap.Get(oKey))
Next
Return Formatter.Format(dSum / lItems)
End Select
End Sub
Any suggestions how to avoid the scientific notation in B4X?
RBS