converting string to int -
redigaffix - 09.01.2013
Hello, im PHP programmer since 3 years now, i'm studying little pawn to create an gamemode, pawn is easy, but i am trying to get a result from mysql, and i get it. The table is an int, and its value ist 3000,, i get the value as string, i need to convert it to int for using the value in the function givePlayerMoney(), i use strval() but it returns me "3" only :S i dont understand why.
Re: converting string to int -
Sinner - 09.01.2013
Show us how you fetch the value. If the string contains '3000' and you use strval(string) it will return the integer 3000.
Re: converting string to int -
redigaffix - 09.01.2013
The table has the value 3000 an int, i get it as string "3000" and i convert it to int and then it returns me 3 only. I am studying right now and can't show you the code, but later arriving at home i show you.
Re: converting string to int -
Sinner - 09.01.2013
Quote:
Originally Posted by redigaffix
The table has the value 3000 an int, i get it as string "3000" and i convert it to int and then it returns me 3 only. I am studying right now and can't show you the code, but later arriving at home i show you.
|
If you are 100% sure it's returning '3000' as a string you're probably using strval() incorrectly. Also, make sure the block size for your string is big enough, if you define a string with size 1 it cannot hold more than 1 character.
Example:
pawn Код:
// Good
new string[9]; // Highest number = 999999999
// Bad
new string[1]; // Highest number = 9
Re: converting string to int -
redigaffix - 09.01.2013
But suposing this is right, it's an int that i want to save in a var, also int is:
new money;
That shoulde be done, or am i right? cause i think money can hold this for example:
money = 6000;
without problems, but why when i convert the string to an int? i dont know why it would't work.
Re: converting string to int -
Konstantinos - 09.01.2013
Debug it.
Re: converting string to int -
redigaffix - 09.01.2013
I think Sinner theory is right, cause i get the SQL string into a string var, this string must be same size or bigger, later i gonna try it Sinner, i think it's that, later i tell you.
Re: converting string to int -
redigaffix - 09.01.2013
Problem solved, thanks all!