Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Formatting float?
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Wed 15 Dec 2004 07:45 PM (UTC) |
Message
| I'm using what_percent to display health also in a percent.
pager_printf_color(ch, "&OHealth&c: &G%s", num_punct(ch->hit) );
pager_printf_color(ch, " &wof &g%s &z(&W%-4f&w%%&z)\n\r", num_punct(ch->max_hit), what_percent(ch->hit, ch->max_hit) );
float what_percent( float x, float y)
{
float z=0;
float n=0;
z = (y/100);
/* z now equals 1% of y */
/* How many times will Z go into X ? */
n = x/z;
return n;
}
But it displays 6 decimal places, which is far too many. Without changing the what_percent function (so I can use it for math later on) how do I format it to show only 2 decimal places? As you can tell I can't seem to format it like normal. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
Posted by
| Greven
Canada (835 posts) Bio
|
Date
| Reply #1 on Wed 15 Dec 2004 07:52 PM (UTC) |
Message
| You would use something like this:pager_printf_color(ch, " &wof &g%s &z(&W%-4.2f&w%%&z)\n\r", num_punct(ch->max_hit), what_percent(ch->hit, ch->max_hit) );
I'm at work and don't do it that often, but that should work. You can check the man pager ofr sprintf I beleive and it will detail the information needed.
|
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | Top |
|
Posted by
| Zeno
USA (2,871 posts) Bio
|
Date
| Reply #2 on Wed 15 Dec 2004 08:00 PM (UTC) |
Message
| Yeah that worked, thanks. Didn't see anything in the man. |
Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
10,512 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top