Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

subtracting float from long

Status
Not open for further replies.

AndyDoyle

Programmer
Jan 31, 2003
5
US
I have a small problem of subtracting a float value from a long.

When I run the program because cust bal is a float and credit limit is a long when I come to subtract one from the other it isn't working because cust bal is not bigger than credit limit
ie.
first record:-
-2407.629 - cust.cust_bal
538969064 - cust.credit_limit
second record:-
99173.45 - cust.cust_bal
538978064 - cust.credit_limit

I have to process the record if the balance exceeds the limit etc...

Can anyone see my problem?
Thanks.
 
You can cast variables to the same type before doing arithmatic to better predict the outcome, but I think compilers cast to the higher precision type automatically.

I don't think this answers your question. Could you post the part of code in question? ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Please post your code, but why don't you just use a float for credit limit too?
 
Hi,

try this:

long CreditLimit;
float CustomerBalance;

CustomerBalance = -2407.629;
CreditLimit = 538969064;
printf("%ld\n",long(CreditLimit-CustomerBalance));

CustomerBalance = 99173.45;
CreditLimit = 538978064;
printf("%ld\n",long(CreditLimit-CustomerBalance));


Output:
538971471
538878891
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top