Jump to content
  • 0

How to convert number when max int


Napster

Question


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  196
  • Reputation:   72
  • Joined:  12/12/11
  • Last Seen:  

i need help create function convert zeny

 

when query sum zeny over 2147483647 from zeny log SQL

query_sql "SELECT SUM(`amount`) FROM `zenylog`WHERE `id` > '0' LIMIT 1", .@sum;
if(.@sum > 2147483647) {
	set .@sum$, " + .@sum;
	mes "" + .@sum$ +" billion";
}

npc can't show over limit 2147483647

 

thank you for adv

Edited by Napster
Link to comment
Share on other sites

7 answers to this question

Recommended Posts


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

you can use insertchar to insert something in the string

insertchar(<string>,<char>,<index>)

 

like this :D

function format_number;
	mes format_number( "100000", "," );// display 100,000
	close;

function format_number {
	.@num$ = getarg(0);
	.@format$ = getarg(1);
	.@len = getstrlen( .@num$ );

	for ( .@i = ( .@len%3 ? .@len%3 : 3 ); .@i < .@len; .@i += 4 ) {
		.@num$ = insertchar( .@num$, .@format$, .@i );
		.@len++;
	}
	return .@num$;
}

I forgot the function in the main repo..

//////////////////////////////////////////////////////////////////////////////////
// Returns a number with commas between every three digits.
// -- callfunc "F_InsertComma",<number>
// Examples:
//    callfunc("F_InsertComma",7777777)  // returns "7,777,777"
//////////////////////////////////////////////////////////////////////////////////
function	script	F_InsertComma	{
	set .@str$, getarg(0);
	for (set .@i,getstrlen(.@str$)-3; .@i>0; set .@i,.@i-3)
		set .@str$, insertchar(.@str$,",",.@i);
	return .@str$;
}

it's better D:

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

Are you having issues where a single entry in the sql db has an amount greater than max int? If so then theres nothing we can do unless you increase the size of max_int in the src by maybe converting it to uint64 or something. Edit: Althought this shouldn't be the issue as zenylog's amount is: int(11) which limits it to the max_int you specified.

 

If your having issues finding a way to actually calculate the sum of ALL the sql entries together, then there is a way to do that. However to do so requires a loop and only pulling 1 query at a time. Let me know which is the issue D:

Edited by GmOcean
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  196
  • Reputation:   72
  • Joined:  12/12/11
  • Last Seen:  

thankyou sir :)

Link to comment
Share on other sites


  • Group:  Developer
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  2407
  • Reputation:   613
  • Joined:  07/05/12
  • Last Seen:  

if you just want to display the total you could store the value in a string variable (it's allowed)

query_sql "SELECT SUM(`amount`) FROM `zenylog`", .@sum$;
mes .@sum$ +" billion";
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  31
  • Topics Per Day:  0.01
  • Content Count:  666
  • Reputation:   93
  • Joined:  04/27/12
  • Last Seen:  

Oh? I didn't know that was allowed. Well, time to delete this annoyingly complicated function xD since it's no longer of use. And yeah, trust me, it is a pain to make stuff like this so take the easy route.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  196
  • Reputation:   72
  • Joined:  12/12/11
  • Last Seen:  

ask some question

when use string variable, how to can support or create function format_number 

ex: 1,000,000,000

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  11
  • Topics Per Day:  0.00
  • Content Count:  196
  • Reputation:   72
  • Joined:  12/12/11
  • Last Seen:  

great working thankyou again  /ok

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...