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

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

如何修復 php 中的拼寫錯誤

如何修復 php 中的拼寫錯誤

PHP
LEATH 2023-08-11 17:05:28
今天是個好日子。我的代碼有問題。我正在嘗試制作一個簡單的程序,將數字轉換為單詞,但我在代碼中遇到了以下問題。$num = 900.00;$exp = explode('.', $num);$f = new NumberFormatter("en_US", NumberFormatter::SPELLOUT);$num_words = ucfirst($f->format($exp[0])) . ' point ' . ucfirst($f->format($exp[1]));我期待的輸出九百讀這是我得到的九百點零這是錯誤注意:未定義的偏移量:1有人可以幫我弄這個嗎。我正在努力尋找答案。謝謝大家
查看完整描述

1 回答

?
慕森王

TA貢獻1777條經驗 獲得超3個贊

您需要if else像這樣使用來檢查點后面的數字。如果為零或小于 1,則不要使用point單詞


$num = floatval(900.00);

$exp = explode('.', $num);

$f = new NumberFormatter("en_US", NumberFormatter::SPELLOUT);

// check the number if the number behind point/comma is less than 1

if(count($exp) == 1){

    $num_words = ucfirst($f->format($exp[0]));

}else{

// other than that print with point

    $num_words = ucfirst($f->format($exp[0])) . ' point ' . ucfirst($f->format($exp[1]));

}


查看完整回答
反對 回復 2023-08-11
  • 1 回答
  • 0 關注
  • 141 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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