这听起来像是一场怪异的斗争,而且实际上很容易做到,但是我找不到将字符串格式的十六进制转换为浮点数的有效方法。
我的例子是: 406ea716
如果使用以下网站之一进行转换,则会得到3.728948。
http://www.h-schmidt.net/FloatConverter/IEEE754.html http://gregstoll.dyndns.org/~gregstoll/floattohex/
我尝试了在互联网上找到的每段代码,但不会返回相同的结果。
NodeJS中是否存在执行相同转换的模块?如果没有,我该怎么办?
谢谢您的帮助。
不需要模块:
var hex = '406ea716';
// transform the hexadecimal representation in a proper js hexadecimal representation by prepending `0x` to the string
// parseInt() - because your example was an integer.
var num = parseInt( '0x' + '406ea716');
console.log( num );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2046 次 |
| 最近记录: |