Like Tree2Likes

Meet some problem in C++ programming

This is a discussion on Meet some problem in C++ programming within the C Programming forums, part of the General Programming Boards category; Originally Posted by Ngoo Jia Xun Use ceil and float to round up? Code: lround((double)cents/(double)x); Where "cents" is the monetary ...

  1. #16
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Ngoo Jia Xun View Post
    Use ceil and float to round up?
    Code:
    lround((double)cents/(double)x);
    Where "cents" is the monetary value and x is an integer divisor. If x is a float, you do not need to cast it to a double. Otherwise, both those casts are necessary -- and, nb, do not do this:

    Code:
    lround((double)(cents/x));
    Quote Originally Posted by nonoob View Post
    This does not sound like a cumulative rounding error but instead the programmer elected to use floating point constant when there was no use of floating point warranted. An integer divide-by-10 would do the job. And I bet those Patriot Missile programmers get paid more than I do.
    Implying somebody (perhaps) got thru school without having this point brought home properly. Hopefully we saved some lives here today .

    I always feel overzealous about this one, lol (thanks CornedBee & mike65535).
    Last edited by MK27; 06-14-2011 at 09:21 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #17
    Registered User
    Join Date
    Jun 2011
    Posts
    5
    Code:
    	adjustedAmount = lround((double)amountPayable/(double)amountPayable);
    Like this? Sorry, still newbie in C..

  3. #18
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by nonoob View Post
    And I bet those Patriot Missile programmers get paid more than I do.
    I'd say that's a safe bet... Consdering that an army Private earns more than most Programmers (in Canada, at least).

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem - 2 elevators, when do they meet ?
    By apacz in forum Contests Board
    Replies: 1
    Last Post: 12-03-2005, 10:48 AM
  2. old HD, meet new computer
    By deathstryke in forum Tech Board
    Replies: 12
    Last Post: 12-05-2002, 05:04 PM
  3. if you could meet someone from here in live, who would it be?
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 01-19-2002, 06:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21