I’m not sure this qualifies as a better idea Emile but it works for me . When I create the SQLite table, I store currency values as the SQLite column type REAL. Then I retrieve them using .CurrencyValue as you are doing.
Yes Alberto, I checked the values and they are correct. Worst, I used StringValue and get the same result. I think I’m goin’ to send this project to bed and come back to it tomorrow. (after a reboot).
Can you explain what ‘correct’ means?
You see 123,45 or do you see 123.45 on the database?
Usually when people don’t get the cents is because Xojo sees a comma instead a period and drops the rest. Note: this is just a guess.
Data stored in a database should always use “.” as the decimal separator. Store data according to the standards. Then display it according to the locale.
You like to refer to literature in documentation, forums and the like. However, when you need an answer yourself, you often like to take the easy way out…
Thisa topic was discussed at length some time ago on the SQLite Users Forum. My possibly faulty recollection is that there wa a suggestion to use INTEGER, but multiply values by 10000, and do the appropriate division later to restore pounds and pence. The extra two decimal places then cover rounding errors.
You haven’t provided any code. I’m happy that your efforts give you the result you needed.
Yes, currencty.ToString with a locale will give you the money (Euro in this case) symbol, but that is not a problem related with your database.
You are confused and may confuse other people. SQLite uses REAL, you can define as Currency if you want. And you can even save invalid data to it like “money123”.
My guess (again, as you didn’t provide any code) is that you are saving Strings (as you said before) like 3,45 and to fix your currency problem you are reading now as String and converting that to currency, then using Currency ToString to get the Euro symbol without you adding it.
That’s in the Xojo realm. Native Xojo type “Currency” behind the scenes is just an Int64 with a fixed decimal of 4 digits, that means that the value 12.34 is stored internally as an integer 123400 and converted by Xojo to a double as (Currency = int64Value / 10000) for intermediate calculations.
But as Alberto said in the SQLite realm, the primitive types are simple as TEXT, INTEGER, REAL and BLOB and depending on how you make your code trying to put a “currency” there your values can end in the DB as REAL or TEXT. SQLite stores values as Javascript or PHP or Python… it does not care, it decides the type on the fly depending on the source value.
So a “currency” field in SQLite can receive a string “12,34” or a float 12.34
And it does not compute correctly with incorrect non-standard values as “12,34” discarding decimals as it only accepts point for a dynamic conversion to float.
There are 2 layers that confuse people, the backend storage layer and the frontend presentation layer. Because due to locale you may see “12,34” it does not mean that it is stored as that.