Android Question Float type is wrong!

LucaMs

Expert
Licensed User
Longtime User
I read some posts on this topic.
I have always read that it is not in the internal representation.

I rather think so.

Create a SQLite table with a field of type:
test 1) Column data type = NUMERIC
test 2) Column data type = TEXT

Insert some values:
B4X:
Private Query As String
Query = "INSERT INTO TB (Price) VALUES (?)"
Price = 10.1
DB.ExecNonQuery2(Query, Array As Object(Price))


You'll get:

1) NUMERIC - NOT ROUNDING
Listview data (loaded from DB): correct
DB data: WRONG

1a) NUMERIC - ROUNDING INTO THE QUERY
Listview data (loaded from DB): correct
DB data: correct

1b) NUMERIC - ROUNDING THE FLOAT VALUES SETTING THE VARIABLES
Listview data (loaded from DB): correct
DB data: WRONG

-------------------------------------------------------------------

2) TEXT - NOT ROUNDING
Listview data (loaded from DB): WRONG
DB data: WRONG
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
But how many know that the value returned by Log is different from what a Java user would get for the same number? Who is right in this case? Does the conversion to double made by B4A brings something useful?
I think that it doesn't really matter. Developers should 1. remember that a binary floating point cannot accurately represent decimal values.
2. use NumberFormat if they want to convert a number to a string.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I think, rightly :D, that it should be specified here:

upload_2014-7-14_12-19-57.png


and I also think that 0 is misleading.
 
Upvote 0
Top