Results 1 to 6 of 6

Thread: casting question! Is this roudning to the nearest integer?.:Resolved:.

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    Question casting question! Is this roudning to the nearest integer?.:Resolved:.

    Hello everyone!
    I'm reading some exericses and it wants me to round the number to the nearest integer. Okay this is quite easy I thought, but does this mean if i have:
    34.6 to print 34
    or does it mean
    34.6 to print 35?
    my code does the first thing, it prints 34 not 35.

    Code:
    double x = 34.6;
    cout <<"x: " << static_cast<int>(x) << endl;
    this just truncates the decimal number and prints 34! is this right?
    Thanks for listening,
    Last edited by voidflux; Jul 20th, 2003 at 12:54 PM.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width