Rails钱圆美分

时间:2017-09-26 14:33:10

标签: ruby-on-rails money-rails

我试图在没有美分的情况下花钱,但我希望金额总是(ceil)。

我做完了:

steambot.js

但它仍然会返回“$ 123”而不是“$ 124”。

2 个答案:

答案 0 :(得分:0)

您是否尝试将舍入模式设置为ROUND_UP,而不是ROUND_CEILING

答案 1 :(得分:0)

我正在查看Money gem并且格式似乎没有利用任何舍入规则。它只是砍掉美分以获得“绝对”价值。

function autoReply() {
var interval = 5;    //  if the script runs every 5 minutes; change otherwise
  var date = new Date();
  var day = date.getDay();
  var hour = date.getHours();
  if(!isLabel('out-of-office')){GmailApp.createLabel('out-of-office');}//out-of-office label eliminates duplicate replies
  if ([5,6].indexOf(day) > -1 || (day == 0 && hour < 8) || (day == 4 && hour >= 19)) {
    var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
    var threads = GmailApp.search('is:inbox after:' + timeFrom);
    for (var i = 0; i < threads.length; i++) {
      if (threads[i].isUnread() && threads[i].getLabels().indexOf('out-of-office')==-1)
      {
        threads[i].reply("Hello! Our offices are closed for the weekend. I will be monitoring my emails sporadically and will do my best to answer any urgent inquiries. If this is not urgent, I will reply to your email on Sunday morning. Thank you for your patience. Now go have a great weekend!");
        threads[i].markImportant();
        threads[i].addLabel('out-of-office');
      }
    }
  }}

function isLabel(labelname)
{
  return GmailApp.getUserLabelByName(labelname);
} 

来源:https://github.com/RubyMoney/money/blob/master/lib/money/money/formatting.rb

试图为您找到一个解决方法,也许可以将其作为Rails模型的方法添加:

formatted = self.abs.to_s
...
if rules[:no_cents] || (rules[:no_cents_if_whole] && cents % currency.subunit_to_unit == 0)
  formatted = "#{formatted.to_i}"
end