Thread: Help with type casting

  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    1

    Help with type casting

    So I have been fiddling around with this trying to get it to put out a float but it won't. Any help would be appreciated.

    net = ((float)inc - (inc * tax1)/100);

  2. #2
    Registered User
    Join Date
    Dec 2013
    Posts
    241
    first of all , net has to be declared as float at the first place, otherwise the computer will round it down to something else.
    second of all, assuming that tax1 is an integer too, it has to be casted as well
    three, if inc is not float, it has to be casted in all of it's instances.

    so we get
    net =((float) inc - ((float) inc * (float) tax1)/100) and making sure that we declared float net; at the start

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advantages of c++ type casting over c type casting
    By kaibalya2008 in forum C++ Programming
    Replies: 10
    Last Post: 05-05-2009, 11:09 AM
  2. type casting
    By rambos in forum C Programming
    Replies: 5
    Last Post: 03-04-2008, 01:15 PM
  3. difference between type conversion and type casting
    By Bargi in forum C Programming
    Replies: 1
    Last Post: 01-23-2007, 03:17 AM
  4. Type casting
    By Lionmane in forum C Programming
    Replies: 28
    Last Post: 08-20-2005, 02:16 PM
  5. Type Casting
    By joshdick in forum C++ Programming
    Replies: 6
    Last Post: 09-06-2003, 08:30 PM