converting string to int
#1

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.
Reply
#2

Show us how you fetch the value. If the string contains '3000' and you use strval(string) it will return the integer 3000.
Reply
#3

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.
Reply
#4

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
Reply
#5

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.
Reply
#6

Debug it.
Reply
#7

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.
Reply
#8

Problem solved, thanks all!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)