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
Post a Comment