Jump to content
  • 0

How to round to nearest 2 digit?


Zirius

Question


  • Group:  Members
  • Topic Count:  10
  • Topics Per Day:  0.00
  • Content Count:  23
  • Reputation:   1
  • Joined:  07/22/14
  • Last Seen:  

Hello! I am trying to announce the current rates of my server. But they are not multiple of 100.

If my base rate is 175 I want to show 1.75 by dividing by 100. But when I divide it floor() the result, resulting only on showing 1.

How to do this?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

.@i = 175;
announce sprintf( "%d.%02dx",( .@i / 100 ),( .@i % 100 ) ),_bc_all;
end;

you can also try like this.

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  420
  • Reputation:   89
  • Joined:  01/30/12
  • Last Seen:  

I don't think it's possible to make a float number in script. I think it only supports integers. So you need to trick with integers and string texts. Ofc if you don't want to read the value from your settings, then simply write the value in the text, but I suspect you want to read the val from confs.

 

You can try the following (.@x = rate):

announce "The current base rate is: "+ .@x/100 +"."+ .@x-((.@x/100)*100),0;

(if the script does the flooring right after the division, then this should return first the integer part, then after the point the rest)

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  74
  • Topics Per Day:  0.02
  • Content Count:  420
  • Reputation:   89
  • Joined:  01/30/12
  • Last Seen:  

@Emistry Yes, your's much better :D I always overcomplicate stuff :D

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...