0
int main()
{
int antal_sekunder=9;
double minuttakst=0.019000;
int takst_enhed=60;

double   antal_minutter, beloeb, beloeb1;
    antal_minutter = (double)antal_sekunder / (double)takst_enhed;
    beloeb1 = ((antal_minutter * minuttakst) * 10000.0) + 0.5 ; //This is used for rounding up to 4 decimals. 

    printf("\n beloeb1 = %lf", beloeb1);
    printf("\n (long)beloeb1 = %ld",(long) beloeb1);
beloeb1 = beloeb1/10000.0;
    printf("\n beloeb1 = %lf", beloeb1);


return 0;
}

Output:
beloeb1 = 29.000000
(long)beloeb1 = 28
beloeb1 = 0.002800 // The out put should be 0.002900

I need the logic, that which will round the double value upto 4 decimal part.
If any one know other logic for rounding the double value upto 4 decimals, please help me.

thanks in advance.

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by jephthah
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.