gpt4 book ai didi

julia - 使用 Julia,如何以工程符号格式化阿伏伽德罗常数(或其他数字)?

转载 作者:行者123 更新时间:2023-12-04 14:53:56 26 4
gpt4 key购买 nike

工程记数法与科学记数法的不同之处在于:

  • 指数始终是 3 的倍数,并且
  • 小数点左边的数字被缩放到范围从 1 到 999。

  • 我的用例要求在小数点右侧指定 0 到 13 位数字。默认值为 4。
    以下是所需的示例:
    const Avogadro = 6.022140857e23

    str = eng_notation(Avogadro, digits=0)
    # str = "602E+21"

    str = eng_notation(Avogadro, digits=1)
    # str = "602.2E+21"

    # Default 4 digits to right of decimal point.
    str = eng_notation(Avogadro)
    # str = "602.2141E+21"

    str = eng_notation(Avogadro, digits=10)
    # str = "602.2140857000E+21"

    # Negative and fractional numbers should also work.
    str = eng_notation(-0.01234567, digits=7)
    # str = "-12.4567000E-03"
    有什么建议?
    编辑:我将要求更新为小数点右侧的 0 到 13 位数字(之前从 0 到 15)。

    最佳答案

    使用 NumericIO.jl包裹

    julia> using NumericIO

    julia> const Avogadro = 6.022140857e23;

    julia> formatted(Avogadro, :ENG, ndigits=4, charset=:ASCII)
    "602.2E21"

    julia> formatted(Avogadro, :ENG, ndigits=4)
    "602.2×10²¹"

    关于julia - 使用 Julia,如何以工程符号格式化阿伏伽德罗常数(或其他数字)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54000507/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com