PHP and numbers problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

PHP and numbers problem

Post by Calimero »

Situation is as follows:

I have number 10, and I want it 20 times to multiply it self and after each time it does so, to write the result on the page.


After some time(s) it does not output plain "100000000000000000000" format but "1.E+20".

This comes to me as a big problem because of this code:

Code: Select all

$the_number_above = /* ex. */ 100000000000000000000

echo $slice_the_end = substr( $the_number_above, -2 );
Outputs: "20" as an integer - it outputs the value of the exponent, and that is what I don't need - anyone has an idea how to beat this problem.


My question is how to instruct ( or prevent ) php to present in this way.

Been looking in the php.ini and httpd.conf, no luck.

PHP 5, Apache 1.23.xx ( I think - for apache ).


Thanks Ahead !
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that "number" is too large for integers in php. You need to get big number support... but why do you need it?

Your number is converted to a double, which is a floating point system. It's no longer an integer by that point.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

I need some system that uses numbers as co-ordinates ( or reference )
so I need to preserve the exact structure of the number.

I was thinking to use STRING for echo-ing but the number I have to preserve in order to apply mathematical calculations.

Any ideas - ways to do this - is it possible?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

unless your coordinate system has trillions of units in dimensions on screen at once, use a "multiplier". That's how games have done it for many many years. The "current multiplier" tells the system where to translate all coordinates from a given point of arrangement in space.
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

Don't quite follow - can you explain this a bit.

If possibly ( and if it is short ) on some minor example.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

transform the extradimensional information into local space.
Post Reply