javascript - PHP floatval bizarre parsing -


i have calculations on client side javascript.

var total = (((3 * 24) / 100) + 3); //result 3.7199999999999998

i need store 3.7199999999999998 number in database is. database on mysql, use doctrine 2 orm, , entity has precision set /** @column(type="decimal", precision=32, scale=16, nullable=false) * */, after saving see in database number 3.72, wtf ? after checking found doctrine uses floatval , after executing floatval(3.7199999999999998) 3.72!! why?

is there workaround ? telling doctrine not use floatval , store value is? dont want use varchar column.

thanks in advance!

3.72 correct value. 3.7199999999999998 result due floating-point imprecision in javascript (see: how deal floating point number precision in javascript?). i'd suggest using tofixed() in javascript code avoid this.

var total = (((3 * 24) / 100) + 3).tofixed(2); 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -