S
SamL
I need to convert a floating point number to a 64 bit integer (long
long). How to do that in perl? Thanks.
long). How to do that in perl? Thanks.
You will need to specify a little more about where these numbers are
coming from. Probably you want perldoc -f pack.
Ben
The number comes from calculation. For example:
my $a = 2.0**37;
Here I cannot use 2**37 directly since the result is -1.
I have found a way to "convert" it although I think there should be a
better way:
my $b = sprintf ("%.0f", $a);
use bigint;
$a = 2.0**37;
print int($a),"\n";
137438953472
That was my interpretation of the question, too. But it seems I was
mistaken.
The result of this is a string, not a 64 bit integer.
And the result of this is a bigint, which is also not the same as a 64
bit integer.
Perl can also be compiled to use 64 bit integers on most platforms.
But the real question is: What is the 64 bit integer for? Until
this is known, there is no way to tell whether a real 64 bit int is
needed or string or a bigint (or
maybe even a float) can be used instead.
hp
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.