The numbers in each column come from the same source, but they are often displayed as two wildly different numbers!
Can anybody explain why, and how I can make sure that any numbers I display with COLUMN_TYPE_NUMBERS are as precise as can be?
I'm not sure if it's the MyNumberString.As(Float) that is problematic, or B4XTable munging the numbers.
Who knows?
This has been resolved with the use of a column formatter (B4XFormatter). Check out the attached app to see how it works.
There's also a random number generator that gets you anything from "0.0" to "999999999.999999999." It's handy for testing purposes. (Might could be made faster, but it's already fast enough.)
Public Sub randomStringOfNumbers(len As Int) As String
Dim numbers As String = "0123456789"
Dim theNum As StringBuilder
theNum.Initialize
Dim numChars As Int = Rnd(1, len)
Dim i As Int
For i=0 To numChars-1
theNum.Append(numbers.CharAt(Rnd(0,numbers.Length-1)))
Next
Return theNum
End Sub
More simple:
Public Sub randomStringOfNumbers(len As Int) As String
Return "0123456789".SubString2(0, len)
End Sub
I'm getting the number as a string, so NumberFormat2 doesn't help. I'd like to have them as numbers so they sort properly, so I'll look into the B4XFormatter.
I meant in your randomStringOfNumbers, which returns a string.
But you cannot insert a string-number in a numeric column and be able to obtain the desired formatting.
The number to insert must be... a number (better a Double) and then format it using B4XFormatter.
Yes, but there's never an actual number (float, double, etc.)... The number sent to the function determines the maximum length of the string of random digits.
But you cannot insert a string-number in a numeric column and be able to obtain the desired formatting.
The number to insert must be... a number (better a Double) and then format it using B4XFormatter.
I take the string generated by the function and turn it into a float to insert into the B4XTable, so there is an Array of Object(string, float) being put into the B4XTable. i.e., there is no string being put into a number column. It's all done properly.
The problem was, it looks like the format of the column is limited to three decimal places or 8-9 digits in length.
Yes, but there's never an actual number (float, double, etc.)... The number sent to the function determines the maximum length of the string of random digits.
I take the string generated by the function and turn it into a float to insert into the B4XTable, so there is an Array of Object(string, float) being put into the B4XTable. i.e., there is no string being put into a number column. It's all done properly.
The problem was, it looks like the format of the column is limited to three decimal places or 8-9 digits in length.
Public Sub randomStringOfNumbers(len As Int) As String
Dim Left As Int = Rnd(0, Power(10, len))
Dim Right As Int = Rnd(0, Power(10, len))
Return NumberFormat2(Left, len, 0, 0, False) & "." & NumberFormat2(Right, len, 0, 0, False)
End Sub
I don't know the final purpose. Theoretically you could set that column as text and pass it numbers formatted with NumberFormat2. It would be the simplest solution.