I have a small PHP webform to store items and prices in a SQLite database.
I store prices in integers, after PHP increases its value *100 (so I indirectly have a rounded to the 2nd decimal price) this way:
$form_Price = intval($form_Price*100);
$query = "insert into items values ($form_Name,$form_Price)";
$results = $db->querySingle($query);
It usually works fine, no issues until today... I got an item with a $2.28 price tag. When I store it using the PHP form, the field show the value = "227" instead of "228". I tried myself different times, I thought there was a rounding mistake somewhere, but it seems I cannot find this bug.
If I insert manually the value into the database as "228" integer, the form using this code
$select_Price = intval($select_Price)/100;
print "Price: $select_price";
shows the correct price "2.28". So I think the problem is somewhere between the PHP form saving the price and the sqlite dabase accepting the query.
I know I should validate and sanitize the forms and the SQL query, but this "thing" is only used by myself as an excercise and it's unreacheable from the internet.
EDIT: As noted by @IncredibleHat replacing intval() with round() actually fixes my problem.