Jump to content
  • 0

How to convert number when max int


Question

Posted (edited)

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

7 answers to this question

Recommended Posts

Posted (edited)

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
Posted

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
Posted

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.

Posted

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

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...