title: Laravel 5.6 how to preserve float and int values in json response?
body: <p>Searching about 20 minutes and still can't find reliable answer how to simply configure json respone for float type.</p>
  
  <pre><code>$array = DB::select('SELECT name, balance FROM ... blah blah blah'); // balance is float
  
  return response()-&gt;json([
     'data' =&gt; $array
  ]);
  </code></pre>
  
  <p>It returns:</p>
  
  <pre><code>{"data":[
     {"name":"bob","balance":"889.37700000000018"},
     {"name":"john","balance":"705.77400000000011"}
  ]}
  </code></pre>
  
  <p>So, as you might guess I want to have float type in this json data for balance values:</p>
  
  <pre><code>{"data":[
     {"name":"bob","balance":889.37700000000018},
     {"name":"john","balance":705.77400000000011}
  ]}
  </code></pre>
  
  <p>I can use standard <code>json_encode()</code> function with <code>JSON_PRESERVE_ZERO_FRACTION</code> flag to solve this issue.</p>
  
  <p>But how to do the same thing with <code>response()-&gt;json()</code> ?</p>
  
  <p>I've tried this sample but it fails and error occurs:</p>
  
  <pre><code>return response()-&gt;json([
        'data' =&gt; $array
     ],
     Response::HTTP_OK,
     [],
     JSON_PRESERVE_ZERO_FRACTION
  );
  </code></pre>