rounding of number using C programming language

rounding of number using C programming language

Page 1 of 1

2 Replies - 7832 Views - Last Post: 28 January 2009 - 05:58 AM Rate Topic: -----

#1 frenz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-January 09

rounding of number using C programming language

Post icon  Posted 28 January 2009 - 03:33 AM

hi good day ..may i ask how can you make a program that can round numbers with decimal points using C programming codes. Rounding it in any decimal places ...
Is This A Good Question/Topic? 0
  • +

Replies To: rounding of number using C programming language

#2 tommod   User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 32
  • Joined: 21-July 08

Re: rounding of number using C programming language

Posted 28 January 2009 - 04:36 AM

You should have a look at the setprecision manipulator in C++.

Have a read of this.

t
Was This Post Helpful? 0
  • +
  • -

#3 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7256
  • View blog
  • Posts: 15,132
  • Joined: 16-October 07

Re: rounding of number using C programming language

Posted 28 January 2009 - 05:58 AM

Depends on if you want to round the value or the display of the value.

For display, in C, printf has a format of decimal precision.

For value, there are some rounding functions. To roll you own, just multiply the number by 10 to the power of digits you want, at 0.5 for rounding, drop the decimal part (cast int), and divide it by the same amount you multiplied by.

This post has been edited by baavgai: 28 January 2009 - 05:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1