我正在使用Stripe並獲取便士貨幣。所以12.90看起來像1290.我想將其轉換爲美元貨幣,但如果我嘗試使用number_to_currency方法,它最終會看起來像1,290.00。有沒有一種方法將完整的字符串轉換爲貨幣,以便在12.90時正確顯示?將便士轉換成帶有導軌的貨幣
我當前的代碼是:
<h4>Total Payment Due: <%= number_to_currency(@user.total_cost)%>
我正在使用Stripe並獲取便士貨幣。所以12.90看起來像1290.我想將其轉換爲美元貨幣,但如果我嘗試使用number_to_currency方法,它最終會看起來像1,290.00。有沒有一種方法將完整的字符串轉換爲貨幣,以便在12.90時正確顯示?將便士轉換成帶有導軌的貨幣
我當前的代碼是:
<h4>Total Payment Due: <%= number_to_currency(@user.total_cost)%>
你也可以用這筆錢創業板:https://github.com/RubyMoney/money
Money.new(100, "USD").format #=> "$1.00"
可能是矯枉過正,但會做你想要什麼。
除以100即可。 – michaelmichael
我想你的意思是12.90而不是12.95開始? – mahemoff