open All Channels
seplocked EVE Technology Lab
blankseplocked php number format problem
 
This thread is older than 90 days and has been locked due to inactivity.


 
Author Topic

WhyAmIPoor
Posted - 2011.06.08 17:23:00 - [1]
 

$xml= simplexml_load_file("https://api.eveonline.com/char/CharacterSheet.xml.aspx?userID=$f23&apiKey=$f24&characterID=$f26");
$isknoformat=$xml->result->balance;
$isk = number_format($isknoformat);

For some reason its not working. $isknoformat gets the right data from the xmlsheet for example 57563524.67

But when i try to echo $isk I get nothing. echo $isknoformat gives 57563524.67

I have no idea at all why it isnt working.

Help?

Lutz Major
Posted - 2011.06.08 18:47:00 - [2]
 

Originally by: WhyAmIPoor
$xml= simplexml_load_file("https://api.eveonline.com/char/CharacterSheet.xml.aspx?userID=$f23&apiKey=$f24&characterID=$f26");
$isknoformat=$xml->result->balance;
$isk = number_format($isknoformat);

For some reason its not working. $isknoformat gets the right data from the xmlsheet for example 57563524.67

But when i try to echo $isk I get nothing. echo $isknoformat gives 57563524.67

I have no idea at all why it isnt working.

Help?

For ISK 57563523.67 I'd guess the answer lies in the function 'number_format'. I'm no PHP guy, but isknoformat is supposedly a string, wheras the function will need a number parameter?!?

Trenker
Posted - 2011.06.08 19:09:00 - [3]
 

$isknoformat=$xml->result->balance;

returns an object, which cannot be formated by number_format. The automatical casting into a string is only done on echo calls and similar. so you should try something like that
$isknoformat = (string) $xml->result->balance;
$isk = number_format($isknoformat);

WhyAmIPoor
Posted - 2011.06.08 22:50:00 - [4]
 

Much love that was it, $isknoformat was a string not a integer adding intval() worked

$isk = number_format(intval($isknoformat));


Peter Powers
FinFleet
Raiden.
Posted - 2011.06.09 05:24:00 - [5]
 

you should read again what Trenker said ;)

Trenker
Posted - 2011.06.09 08:04:00 - [6]
 

Originally by: Peter Powers
you should read again what Trenker said ;)

For some reason, PHP calls the __toString method, whenever you cast an object to a primitive. So WhyAmIPoors code will work, because calling

$isk = intval($xml->isk);

is internally processed as

$isk = intval( strval($xml->isk) );

Works for all type conversions, including (float) and (bool). That's maybe a little weird but at least it makes things work for non professionals Very Happy.

Mikk36
Caldari
Posted - 2011.06.09 11:34:00 - [7]
 

Edited by: Mikk36 on 09/06/2011 11:38:09
I would suggest suing floatval() since a lot of times, the numbers in EVE are bigger than what 32bit integers allow. Also, the ISK amount is a float, not integer value.

Hel O'Ween
Men On A Mission
EVE Trade Consortium
Posted - 2011.06.09 15:07:00 - [8]
 

Originally by: Mikk36
Also, the ISK amount is a float, not integer value.


Disclaimer: I don't know PHP so I'm not sure if this is possible in PHP

It's no float either. If possible, it should be treated as a currency datatype, as floats are not guaranteed to be accurate. See the big red warning for PHP floats (which isn't PHP-specific but true for all IEEE floating point number implemetations).

I just recently had to help a work mate who was going to lose her mind, because numbers didn't add up correctly. The above mentioned limitation caused the problem.

Tonto Auri
Vhero' Multipurpose Corp
Posted - 2011.06.09 16:19:00 - [9]
 

Originally by: Hel O'Ween
Originally by: Mikk36
Also, the ISK amount is a float, not integer value.


Disclaimer: I don't know PHP so I'm not sure if this is possible in PHP

It's no float either. If possible, it should be treated as a currency datatype, as floats are not guaranteed to be accurate. See the big red warning for PHP floats (which isn't PHP-specific but true for all IEEE floating point number implemetations).

I just recently had to help a work mate who was going to lose her mind, because numbers didn't add up correctly. The above mentioned limitation caused the problem.


Unfortunatelly, it IS float :/
Why? Ask EVE devs...

Speaking of PHP - http://php.net/bcmath

Hel O'Ween
Men On A Mission
EVE Trade Consortium
Posted - 2011.06.10 09:48:00 - [10]
 

Originally by: Tonto Auri

Unfortunatelly, it IS float :/
Why? Ask EVE devs...



In EVE's DB - yes (i.e. eventually can't get a wallet back to 0 ISK, it will always reamin 0.01 ISK).

But not in the API data. It's a string there and the numerical datatype you convert it to. So, be nice and make it (the equivalent of) Currency and you're good on your side.

PsyKzz
Posted - 2011.06.11 18:05:00 - [11]
 


$xml= simplexml_load_file("https://api.eveonline.com/char/CharacterSheet.xml.aspx?userID=$f23&apiKey=$f24&characterID=$f26");
$isknoformat=(float)$xml->result->balance;
$isk = number_format($isknoformat);


That should work.


 

This thread is older than 90 days and has been locked due to inactivity.


 


The new forums are live

Please adjust your bookmarks to https://forums.eveonline.com

These forums are archived and read-only