i have a question that i cannot resolve by myself, and im was thinking that i can be pushed here to get the best precision calculating vat prices in php and mysql.
For example:
I have the gross price = 1199
The TAX Amount is = 24
to extract the vat = 1199 / 1.24 = 966.93548387096 round(966.93548387096,2) = 966.94
ok
now this value will be saved in mysql with decimal 12,2
Now, if you add the vat = 966.94 * 24 / 100 = 232.0656 round(232.0656,2) = 232.07
Final = 966.94 + 232.07 = 1199.01
My question is, how can i get 1199 without floating ?
Any help is apreciated.!
UPDATE:
The value saved in database is 966.94 from where is applying the tax vat amount.
an option can be to save the value with 4 decimals when i introduce the prices in the database, but for that i will need to override an array to extact the column and take out the vat.
Like:
$arrResult = array();
$handle = fopen("uploads/csv/".$csv, "r");
if( $handle ) {
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
$arrResult[] = $row;
}
fclose($handle);
}
$titles = array_shift($arrResult);
// need to take out the price and apply price / 1.24 and save the value as 4 decimal in mysql
$keys = array('code', 'price');
$final = array();
foreach ( $arrResult as $key => $value ) {
$final[] = array_combine($keys, $value);
}