Easycore Posted November 24, 2016 Group: Members Topic Count: 36 Topics Per Day: 0.01 Content Count: 220 Reputation: 252 Joined: 04/08/13 Last Seen: August 24, 2023 Share Posted November 24, 2016 Hello, I know that rAthena doesn't support decimal variables, but I would like only display it. For eg: set Something, 5/2; // It will be two So: dispbottom "There are "+Something+" "; And the result: "There are 2.5" I only want to display decimal in messages, and with decimals of 2 digits (eg. 2.12) Regards~ Quote Link to comment Share on other sites More sharing options...
1 Tokei Posted November 24, 2016 Group: Members Topic Count: 16 Topics Per Day: 0.00 Content Count: 664 Reputation: 672 Joined: 11/12/12 Last Seen: 1 hour ago Share Posted November 24, 2016 (edited) You can try this script: function script DivToDecimal { .@x = getarg(0); .@y = getarg(1); .@precision = 2; // The amount of digits to keep after the dot .@mod = pow(10, .@precision); .@left = .@x / .@y; .@right = (.@x * .@mod / .@y) % .@mod; .@result$ = "" + .@left; if (!.@right) return .@result$; // Removes trailing zeroes, for example: // With .@zeroes set to 0, 5 / 2 will output 2.5 // With .@zeroes set to 1, 5 / 2 will output 2.50 .@zeroes = 0; for (.@i = 0; .@i < .@precision; .@i++) { .@digit = .@right % 10; .@right = .@right / 10; if (!.@zeroes) { if (.@digit == 0) continue; .@output$ = insertchar(.@output$, .@digit + "", 0); .@zeroes = 1; } else { .@output$ = insertchar(.@output$, .@digit + "", 0); } } return .@result$ + "." + .@output$; } prontera,154,161,0 script TestNPC 567,{ dispbottom "Your number is: " + callfunc("DivToDecimal", 5, 2); end; } Be careful with overflows if your numbers are too high (this script breaks easily, but for simple divisions it will work out fine). Edit: If you must store the result of your division in a variable, you'll have to do some dirty tricks, for example: Something = 5 * 100 / 2; //... dispbottom "There are " + callfunc("DivToDecimal", Something, 100); Edited November 24, 2016 by Tokei 3 1 Quote Link to comment Share on other sites More sharing options...
Question
Easycore
Hello,
I know that rAthena doesn't support decimal variables, but I would like only display it.
For eg:
set Something, 5/2; // It will be two
So:
dispbottom "There are "+Something+" ";
And the result: "There are 2.5"
I only want to display decimal in messages, and with decimals of 2 digits (eg. 2.12)
Regards~
Link to comment
Share on other sites
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.