Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
guest
Newbie


Joined: 15 Jan 2001
Posts: 7

PostPosted: Wed Dec 24, 2003 9:29 am   

Messing with numbers
 
Specifically, is there any way to make ZMud round a number to the thousands, rather than the ones place?
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Dec 24, 2003 4:15 pm   
 
Yes. Use a rounding formula.

If you provided an example of what you want to do, it would probably be easier to help you do it.
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Wed Dec 24, 2003 4:44 pm   
 
I don't think there is an inbuilt function to round up to the thousand mark. But the following script worked for me:

#alias round {#var loopcount 4;#var roundednumber {%1};#IF (%len(%1)>3) {#IF (%number(%rightback(%1,3))>500) {#WHILE (%number(%copy(%rightback(%1,@loopcount),1,1))=9 AND @loopcount<%len(%1)) {#add loopcount 1};#VAR roundednumber {%concat(%leftback(%1,@loopcount),%eval(%copy(%rightback(%1,@loopcount),1,1)+1))};#LOOP %eval(@loopcount-1) {#var roundednumber {%concat(@roundednumber,"0")}}} {#var roundednumber {%number(%concat(%leftback(%1,3),"000"))}}} {#IF (%1>500) {#var roundednumber {1000}} {#var roundednumber {0}}};#ECHO @roundednumber}

To round, just type: Round <value-to-be-rounded>
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Dec 25, 2003 4:37 am   
 
It would be simpler to just do what your math teacher taught you:
1. Divide by 1000 to get the quotient
2. Find the remainder with modulus division (the operator or the %mod function)
3. If the remainder is 500 or greater, add 1 to the quotient
4. Multiply the result by 1000

No loops are needed. A simple formula will do the whole thing. But I really wanted guest to clarify the intended use, so that there was a better chance the answer would not require further instructions on how to use it.

(@number/1000) + %eval( @number1000 > 499) * 1000
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Thu Dec 25, 2003 12:10 pm   
 
That should show how much attention I paid in maths. And what does modulus do? I don't recall ever learning that in maths.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net