storing number with 2 decimal place in Sqlite3 with python3
(1) By kbk (kbk4588) on 2020-06-14 09:21:25 [source]
My apology if I have not make my question clear. I am asking how to program in python to store number with 2 decimal places. I am using tkinter TTK to display the number. It would appear that tkinter would just accept the native data from the sqlite data with a single digit decimal to display. So my question is how to make it store in sqlite3 database with 2 decimal places. yes I understand using prinf command in sqlite3 or select command to format but not in python programming as in my example.
I am a newbie, am I doing something wrong or do I approach it wrongly?
Just want a simple solution. Thank you.
(2) By Keith Medcalf (kmedcalf) on 2020-06-14 16:04:21 in reply to 1 [link] [source]
Floating Point does not store an arbitrary number of digits after the decimal point.
The "standard" way to cause a floating point number to be "displayed" with exactly 2 decimal digits, even if the trailing one is a zero, has been since at least the middle of the twentieth century, to use an output mask that looks like this: '%12.02f' which causes the number to be formatted (right justified) into a field 12 characters wide with two digits EXACTLY (even if they are 0) after the decimal point.
In other words, this is a USER INPUT AND DISPLAY PROBLEM and has nothing whatsoever to do with SQLite3, which is merely a storage system.