float setting the number of decimal places

I am trying to find out when using float in a calculation how to set the number of decimal places. For example my code below



#include
int main()
{
float x=123.0;
float y=69.0;
float answer=y*x;
printf("the answer is %f
",answer);
return(0);
}



This returns an answer 8487.0000 I would like it not to show all the decimal places. However if the sum has decimal places I would like to select the number of decimal places shown

Thanks

Rodney

Comments

  • : I am trying to find out when using float in a calculation how to set
    : the number of decimal places. For example my code below
    :
    :
    :
    : #include
    : int main()
    : {
    : float x=123.0;
    : float y=69.0;
    : float answer=y*x;
    : printf("the answer is %f
    ",answer);
    : return(0);
    : }
    :
    :
    :
    : This returns an answer 8487.0000 I would [link=http://exzorders.com/10-articles-coin-collections-plr-mystery-bonus/]plr[/link] like it not to show all
    : the decimal places. However if the sum has decimal places I would
    : like to select the number of decimal places shown
    :
    : Thanks
    :
    : Rodney
    :
    :


    I too would like to know the answer!
  • I too would like to know the answer!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion