【问题标题】:In Stylus, How to convert a percentage to integer?在手写笔中,如何将百分比转换为整数?
【发布时间】:2016-07-28 22:50:04
【问题描述】:

有将数字转换为百分比的percentage 函数,但没有number(或integer)函数。

【问题讨论】:

    标签: casting integer percentage stylus


    【解决方案1】:

    使用unit函数:

    unit(10%, number) // 10
    

    【讨论】:

      【解决方案2】:

      使用您的代码unit(10%, number),您将获得:10number。您必须将单位替换为空字符串:unit(10%, '') => 10

      如果你想要百分比的倒数:percentage(.1) => 10%,你必须除以 100:(unit(10%, '')/100) => 0.1

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-17
        • 2019-04-11
        • 2022-12-11
        • 2015-12-16
        • 1970-01-01
        相关资源
        最近更新 更多