亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用php將字符串數轉換為int數

如何使用php將字符串數轉換為int數

PHP
Cats萌萌 2022-10-28 09:16:31
我遇到了問題,為什么當我在 PhpMyAdmin 中轉換 ROUND(4.9813200498132,1) 的數量時會發生這種情況,結果為 5.0,然后當我嘗試在 php 中轉換值時,結果僅為 5。如何使結果 5.0 到 php 端。?是否需要將字符串數字轉換為整數?為了更好地理解,我將與你們分享我創建的示例方程。php中的方程:$first_wtd_item_first_option =  str_replace( ',', '', $high_item_d_wtd_data->total_qty );$first_wtd_item_second_option = str_replace( ',', '', $high_item_a_wtd_data->total_qty );$first_wtd_item_third_option =  str_replace( ',', '', $high_item_b_wtd_data->total_qty );$first_wtd_item_computation1 = $first_wtd_item_second_option + $first_wtd_item_third_option;$first_wtd_item_computation2 = ($first_wtd_item_first_option / $first_wtd_item_computation1);$first_wtd_item_computation3 = $first_wtd_item_computation2 * 100;$first_wtd_item_final_result = (round($first_wtd_item_computation3,1).'%');輸出:謝謝你。
查看完整描述

2 回答

?
HUWWW

TA貢獻1874條經驗 獲得超12個贊

您應該使用 10 倍數,而不是 100,也可以使用number_format()

$first_wtd_item_first_option =  str_replace( ',', '', $number);

$first_wtd_item_second_option = str_replace( ',', '', $number);

$first_wtd_item_third_option =  str_replace( ',', '', $number);


$first_wtd_item_computation1 = $first_wtd_item_second_option + $first_wtd_item_third_option;

$first_wtd_item_computation2 = ($first_wtd_item_first_option / $first_wtd_item_computation1);

$first_wtd_item_computation3 = number_format((float) $first_wtd_item_computation2 * 10, 1, '.', '');

$first_wtd_item_final_result = $first_wtd_item_computation3.'%';

結果:


5.0%


查看完整回答
反對 回復 2022-10-28
?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

你可以使用number_format

$first_wtd_item_final_result = (number_format(round($first_wtd_item_computation3,1), 1).'%');



查看完整回答
反對 回復 2022-10-28
  • 2 回答
  • 0 關注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號