Formatting float?

Posted by Zeno on Wed 15 Dec 2004 07:45 PM — 3 posts, 13,969 views.

USA #0
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.
Canada #1
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.
USA #2
Yeah that worked, thanks. Didn't see anything in the man.