gpt4 book ai didi

java - 数字解析库

转载 作者:行者123 更新时间:2023-12-04 05:38:27 29 4
gpt4 key购买 nike

就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the help center为指导。




9年前关闭。




我在哪里可以获得 智能数字解析器,可以读取一个数字字符串,比如说......

  • 整数形式:-12345
  • 十进制形式:123.45
  • 指数形式:15e-24
  • 十六进制:#CAFEBABE
  • 二进制:b01100101

  • ... 给我一个 足够 表示(从 byte 如果合适,到 GargantuanDouble 如果不合适)?

    我现在正在考虑使用 Java (Android),所以如果是 Java,那就更好了;但我愿意从另一种语言移植一个足够小的库。

    最佳答案

    假设你可以分离 token ,你可以使用 Integer.decode()用于解码数字。

    The sequence of characters following an (optional) negative sign and/or radix specifier ("0x", "0X", "#", or leading zero) is parsed as by the Integer.parseInt method with the indicated radix (10, 16, or 8). This sequence of characters must represent a positive value or a NumberFormatException will be thrown. The result is negated if first character of the specified String is the minus sign. No whitespace characters are permitted in the String.



    例如。
    Integer.decode("0xabcf123"); // hex
    Integer.decode("07651"); // octal
    Integer.decode("123459"); // decimal

    关于java - 数字解析库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11606950/

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