Loading...

在PHP中如何將NAN轉換為0

Temperature: 0 °C

Mark ChangMark Chang
author_tools

首先我會得到NAN是因為我有一個計算結果為0的值然後我讓他除以0,結果就得到了NAN
首先甚麼是NAN?
查了一下Google得到的答案是:

NaN(Not a Number,非數)是計算機科學中數值數據類型的一類值,表示未定義或不可表示的值。

但我其實是想讓NAN變成0,所以用了以下方式:
//假設我有一個陣列數為$a
//假設$b為0
$a_value = !is_nan(array_sum($a)/$b) ? round(array_sum($a)/$b,1) : 0;

最後輸出
echo $a_value;

以上紀錄~
 

#php  #NAN  #將NAN轉換為0  #未定義或不可表示的值  
https://innstory.com/story-在PHP中如何將NAN轉換為0-2583
PHP

Prev
 PDO_PHP__PDOException__Numeric_value_out_of_range_1264_Out_of_range_value_for_column_userip_at_row_1

Next
php檢查陣列中大於0的值 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

刪除已上傳至server的檔案

刪除已上傳至server的檔...

a5 管理系統,難免都會遇到要更新或刪除已經上傳到server的檔案。 總不能只是重新上傳卻又不把舊...

錯誤訊息Division by zero的解決方式

錯誤訊息Division b...

錯誤訊息Division by zero發生的原因是因為除數是導致的錯誤: 解決方式如下: ) 運行...

解決svchost.exe消耗記憶體問題

解決svchost.exe消...

pexelsphotowin55 根據微軟中文知識庫編號5的文件說明:「SVCHOST.EXE是從動...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format