Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
お金の絶対価値を得るには?例えば:
-2.to_money.? = 2.to_money 2.to_money.? = 2.to_money
正または負の属性total_priceがあります。total_price の絶対値を計算したい。
お金に換算する前に絶対値を取ってみてください。
2.abs.to_money
Money::Arithmetic モジュールに組み込まれた絶対値メソッドがあります。
2.to_money.abs == #<Money fractional:200 currency:USD> # true -2.to_money.abs == #<Money fractional:200 currency:USD> # true