Zusee Weekin Zusee Weekin - 3 months ago 19
Javascript Question

Pass decimal values php to javascript using json_encode

I have a php twoD array which is generated from mssql database. I need to pass this array data to javascript. This is the array example:

....
[70] => Array
(
[travelled] => 151.63313641031
[Time] => 2016-08-04 00:00:00
[Date] => 03-08-2016
[Cost] => 13.646982276928
)

[71] => Array
(
[travelled] => 17.437913283984
[Time] => 2016-08-05 00:00:00
[Date] => 04-08-2016
[Cost] => 1.5694121955586
)
...


I used,

json_encode($array,JSON_NUMERIC_CHECK);


The problem is,
In javascript I received numeric value without digits values for cost. Ex: 13, 1

My question is how to pass decimal values php to javascript using json_encode.
Any help would be appreciated.

Answer

Make sure you're not using parseInt() on the Client Side.

Comments