php - Getting the remainder of a round -


i have use case have column in mysql contains number such 12.458.

i need listing of these numbers , need updated in database rounded 2 decimal places, realize still store 3 decimal places in database, mean example gave rounded 12.460.

i know via mysql , data following query no problems; don't want in-case data updated within time gets rounded , time select it.

so thought if doing selecting , rounding php such as..

$amount = round($amount, 2); 

...and yes, data have changed in database again since selected it; that's not important part - important part running - or + operation on amount in database.

so i'm wanting remaining result of round , run operation on mysql field..

so...

12.457 = 12.46 = +0.003 field 12.421 = 12.42 = -0.001 field 

unfortunately table not innodb , cannot lock updates.

is there better way want?

edit: can select , update @ same time updated data select?

create table yourtable     (`existingvalue` decimal(12,3), `extravalue` decimal(12,3)) ;  insert yourtable     (`existingvalue`, `extravalue`) values     (12.458, null) ;  update yourtable set   extravalue = existingvalue - round(existingvalue,2) , existingvalue = round(existingvalue,2) ; select * yourtable  | existingvalue | extravalue | |---------------|------------| |         12.46 |     -0.002 | 

demo


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -