【问题标题】:How can I format a number into human-readable hours and minutes in Google Sheets?如何在 Google 表格中将数字格式化为人类可读的小时和分钟?
【发布时间】:2021-04-20 13:30:02
【问题描述】:

我想将数字(A 列:十进制形式的小时数)转换为人类可读的格式,仅以 15 分钟间隔显示分钟和小时,理想情况下显示“分钟”和“小时”字样" 仅当值大于 0 时。

我尝试应用类似于this one 的方法,但我不是从时间数据开始(只是数字)。

【问题讨论】:

    标签: google-sheets google-sheets-formula


    【解决方案1】:

    这里有几个选项:

    • 落地到 15 分钟:
    =IFERROR(1/INT(A1)^-1&" hour(s) ")
    &IFERROR(1/(MOD(INT(4*A1)/4*60,60))^-1&" minute(s)")
    
    • 四舍五入到 15 分钟:
    =IFERROR(1/INT(ROUND(4*A1)/4)^-1&" hour(s) ")
    &IFERROR(1/(MOD(ROUND(4*A1)/4*60,60))^-1&" minute(s)")
    
    Number of hours Floored to 15-min Rounded to 15-min
    0.25 15 minute(s) 15 minute(s)
    4.5 4 hour(s) 30 minute(s) 4 hour(s) 30 minute(s)
    3 3 hour(s) 3 hour(s)
    0.49 15 minute(s) 30 minute(s)
    3.14 3 hour(s) 3 hour(s) 15 minute(s)
    3.99 3 hour(s) 45 minute(s) 4 hour(s)

    注意事项:

    • IFERROR(1/x^-1) 用于检查非零值。如果为 0,则导致除以 0 错误,该错误被 IFERROR 捕获,然后输出一个空白值。这样我就不必在 IF 函数中重复使用计算。
    • 通过ROUND(x*value)/x 可以实现四舍五入到最接近的“1/x”。在这种情况下,它是最近的四分之一,因此是 1/4。

    【讨论】:

      【解决方案2】:

      这是 Calculuswhiz 的 ROUND 公式的数组公式版本,控制“s”或缺少“s”。将其放在空列的第一个单元格中(例如 B1):

      =ArrayFormula({"Human Readable";IFERROR(1/INT(ROUND(4*A2:A)/4)^-1&" hour"&IF(INT(ROUND(4*A2:A)/4)^-1=1,,"s")&" ") &IFERROR(1/(MOD(ROUND(4*A2:A)/4*60,60))^-1&" minutes")})

      此公式将生成标题和所有列结果。

      您可以根据需要更改公式中的标题文本。

      【讨论】:

      • 啊,数组公式。早该想到的不错。
      • 发帖人并没有特别要求。只是认为这可能是最有效的方法。公式方法本身做得很好。
      猜你喜欢
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-15
      相关资源
      最近更新 更多