×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

precision in C

precision in C

precision in C

(OP)
Hello everyone,

I need to be able to limit(or control) precision of double datatype to 10 decimal places and not more or less. How would i do it? I can also use float or any other datatype, the issue is making precision only 10 decimal places:

0.0123456789

and this is not output formatting.... I am working with a program that does a scientific computation, so precision is important in calculations, not for the display.

Thank you in advance.

RE: precision in C

Guess you need to work in a language like Coral66, Ada or Cobol where the number of decimal places can be fixed.

Assuming fmod behaves the same way as % and that they haven't done it properly for -ve numbers, after each calculation, you could do something like

CODE

x -= fmod (x, 1E-10);
Very expensive though.

RE: precision in C

(OP)
thank you for the idea! it works!

RE: precision in C

Neat!

EvLer,

If the number is greater than or equal to 1 ( or less than 0.1) how should it be rounded?  For example, does

1.12345123451 get rounded to
1.1234512345  (10 digits after decimal) or
1.123451234   (10 significant figures) ?  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close