0
在處理從MySQL
表中檢索到的一些數據後,我收到了一些不尋常的結果。拉取數據後出現奇怪的結果MySQL
我有四個字段類型浮法,兩行。所有的數據是一樣的,你可以看到如下:
Field1 = 5.0, 0.5
Field2 = 5.0, 0.5
Field3 = 5.0, 0.5
Field4 = 5.0, 0.5
我檢索數據,像這樣:
// Get ratings for this event
$eventRating = $event->getEventRatings($event_id);
$organisation = 0;
$valueForMoney = 0;
$facilities = 0;
$funFactor = 0;
$overall = 0;
foreach($eventRating AS $rating){
$organisation = ($organisation + $rating['organisation']);
$valueForMoney = ($ValueForMoney + $rating['value_for_money']);
$facilities = ($facilities + $rating['facilities']);
$funFactor = ($funFactor + $rating['fun_factor']);
}
// Get average of each rating category
var_dump($organisation = $organisation /$ratingCount);
var_dump($valueForMoney = $valueForMoney /$ratingCount);
var_dump($facilities = $facilities /$ratingCount);
var_dump($funFactor = $funFactor /$ratingCount);
所以結果都應該是相同的嗎?
不過的var_dump的結果是:
浮動(2.75)浮點(2.5)浮動(2.75)浮(2.75)
爲什麼$valueForMoney
2.5時,它應該是3?
是正確的,但我想知道爲什麼它改變了它的價值? – crm
$ valueForMoney(small v)總是等於最後的$ rating ['value_for_money']的值(因爲$ ValueForMoney(big V)總是爲零)。所以我猜你最後的評價是5(而不是0.5)? – danielpsc