Created
November 21, 2019 09:04
-
-
Save DQNEO/4eae5db0cdf54139fdf6100de6909a5b to your computer and use it in GitHub Desktop.
PHP floating number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$my_json2 = '{"tax":2.03}'; | |
$decoded = json_decode($my_json2, true); | |
echo $decoded['tax'] . PHP_EOL; | |
$tax_in_cents = round($decoded['tax'] * 100); | |
$response = ['tax_cents' => intval($tax_in_cents)]; | |
echo json_encode($response) . PHP_EOL; // => 203 | |
$tax_in_cents = $decoded['tax'] * 100; | |
$response = ['tax_cents' => intval($tax_in_cents)]; | |
echo json_encode($response) . PHP_EOL; // => 202 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result