【发布时间】:2010-11-05 07:25:49
【问题描述】:
我正在尝试将单精度浮点数转换为构成它的四个字节的 ascii 表示(符号/指数/尾数)。 我当前的代码是:
Integer.toString(Float.floatToRawIntBits(f),16);
Float.floatToRawIntBits 使用相同的字节生成一个整数,然后Integer.toString 以十六进制形式创建 ascii 数字(因此指定了 radix = 16)。我的问题是我总是需要 8 个 ascii 字符加上可选的“-”符号,而 Integer.toString 没有用左侧零填充。
谁能想出一个优雅的解决方案?
谢谢。
【问题讨论】:
标签: java floating-point integer padding