2014-01-12 43 views
0

我在PHP有一些數字:19,6,33,33,5,5number is missing decimal

我想要得到1,196,1333和1,055。

(19.6/100) + 1 = 1.196 

(33.33/100) + 1 = 1.333 

(5.5/100) + 1 = 1.055 

我有這個價值,

$item['tva'] = 1 + ($tvas[$tmpItem]/100); 

而且在JSON我越來越不1.19 1.196爲什麼?

+1

,而您使用期不是逗號,作爲分隔符? – adeneo

+0

你可以檢查你的號碼嗎?請修復您的問題,以便我們可以回答 –

+0

$ tvas = $ _POST ['cmdTva'] = 19,6,33,33,5,5等...我用逗號收到了我的帖子 – user3162341

回答

1

我做了一個工作的例子。

// array with numbers to add 
$numbers = array(19.6, 33.33, 5.5); 

// array to put formatted numbers in 
$result = null; 

foreach ($numbers as $i => $number) { 
    // format number to have 3 decimal values and push to result array 
    $result[$i] = number_format(1 + ($number/100.), 3); 
} 

// decode array to json and force keys 
print json_encode($result, JSON_FORCE_OBJECT); 

這給:

{"0":"1.196","1":"1.333","2":"1.055"} 
相關問題