【问题标题】:Rounding total minutes from a field to populate hours to another field将一个字段的总分钟数四舍五入以将小时数填充到另一个字段
【发布时间】:2019-03-01 03:04:41
【问题描述】:

我正在处理一个可填写的 PDF,需要一个脚本来将填充到表单字段中的总分钟数四舍五入,该字段会将最近的小时填充到另一个字段中。

例如:total minutes displayed as 1240 (field 1) = 20.67 hours, should display 21 hours in field 2.

【问题讨论】:

标签: javascript pdf acrobat


【解决方案1】:

可读代码:

minutes = this.getField('total minutes').value;
fullHours = Math.floor(minutes/60); 
remainingMinutes = minutes % 60;
hoursRounded = fullHours + (remainingMinutes<30?0:1) ;

可读性较差的代码:

Math.round( Math.floor(this.getField('total minutes').value / 30 ) / 2.0)

【讨论】:

    【解决方案2】:

    将以下代码添加到“小时”字段中的自定义计算脚本中。将下面代码中的字段名称替换为您的“总分钟数”字段的实际字段名称。

    event.target.value = Math.round(this.getField('total minutes').value);
    

    【讨论】:

    • 你测试了吗? Math.round 应该如何知道它应该将分钟数舍入到小时数?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-02
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多