I would liketo know how to set the number of decimal places in the below code to 2.

#include <stdio.h>
#include <math.h>
#include <string.h>

int main()  {
int a =2;
int b =4;
int c =6;
int d =8;

int currencyOption;

printf("\n *********************************************");
printf("\n *********************************************");
printf("\n ** Enter the number from the below list    ** ");
printf("\n ** of currency you wish to convert to US$  **");
printf("\n **                                         **");
printf("\n **                                         **");
printf("\n **    1 = Australian dollars.              **");
printf("\n **    2 = British Pounds.                  **");
printf("\n **    3 = Japanese yen.                    **");
printf("\n **    4 = Vietnams dollars.                **");
printf("\n **                                         **");
printf("\n **    Enter Currency number:               **");
printf("\n **                                         **");
printf("\n *********************************************");
printf("\n *********************************************");
printf("\n");

scanf("%d", &currencyOption);
printf("\n");

float xrate;
if(currencyOption == 1) {
    xrate=1.078;
       printf("You want to convert Australian dollars to US$ \n"); }
if(currencyOption == 2) {
    xrate=0.656;
       printf("you want to convert British pounds to US$ \n"); }
if(currencyOption == 3) {
    xrate=98.309;
       printf("you want to convert Japanese yen to US$ \n"); }
if(currencyOption == 4){
    xrate=21025.0;
       printf("you want to convert vietnames dollars to US$ \n"); }

printf("\n");
printf("\n **************************************************");
printf("\n **************************************************");
printf("\n **                                              **");
printf("\n **  Enter the amount you wish to convert to US$ **");
printf("\n **                                              **");
printf("\n **************************************************");
printf("\n **************************************************");
printf("\n");


    float currencyvalue;
printf("\n");

    scanf("%f",&currencyvalue);
    int i=1;
    float result[2];

            int mult = i* 1;
    result[i] = currencyvalue * xrate * mult;
    printf("\n");
    printf("\n");
    printf(" %f To Be Converted\n\n Exchange rate of %f \n\n US$%f will be recieved\n--------------------\n", currencyvalue, xrate, result[i]); 
    printf("\n");



return 0; }

Instead of %f use something like %3.2f
This means you can print 3 digits and two digits after the decimal point.

thank you very much this works perfectly !!!!

Glad to be of help. You could help other people and mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.