node-int64 icon indicating copy to clipboard operation
node-int64 copied to clipboard

String representation of the Int64 representation

Open jorgebay opened this issue 13 years ago • 5 comments

It would be nice to have the string representation of numbers bigger than Math.pow(2, 53) integrated on this module.

jorgebay avatar Nov 21 '13 14:11 jorgebay

:+1: The closest way to currently do this seems to be toOctetString(), but it returns a string of hexadecimal digits; toString() returning the decimal representation even for >2^53 (instead of Infinity) would be nice.

deathcap avatar Mar 29 '14 02:03 deathcap

Version 0.4.0:

$ node
> const Int64 = require( 'node-int64' );
> b = new Buffer([0xff, 0xee, 0xdd, 0xcc, 0xAA, 0xBB, 0x00, 0x99])
<Buffer ff ee dd cc aa bb 00 99>
> (new Int64( b )).toString(10);
'-4822678473342823'
> b = new Buffer([96, 0x8e, 0x9c, 0xc6, 0x83, 0xa5, 0x19, 0x56])
<Buffer 60 8e 9c c6 83 a5 19 56>
> (new Int64( b )).toString(10);
'Infinity'

soulne4ny avatar Jan 31 '17 17:01 soulne4ny

Any update on this issue? I publish hex2decimal to solve this problem. Here is my PR #17

liaozhongwu avatar Apr 27 '17 05:04 liaozhongwu

.toSignedDecimalString() does correct transformation. Then it is quite strange toString() can not do what it is supposed to do.

soulne4ny avatar May 03 '17 11:05 soulne4ny

If you want to convert between 8-byte buffers and decimal strings, you can also use https://github.com/q3boy/int64/pull/1/files

michielbdejong avatar Oct 06 '17 17:10 michielbdejong