CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

float Mul

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MoofCba



Joined: 08 Mar 2004
Posts: 4

View user's profile Send private message

float Mul
PostPosted: Wed Mar 01, 2006 10:34 am     Reply with quote

Dear Friends:

i have two float numbers. One of them have a lot of decimals.
i just want to mul this two floats, but one of them with only two decimals.

Example

A=12.43233
B=67.2

B=A*B but not 12.43233*67.2, i want 12.43*67.2 how can i do that???.

Thanks i hope you can understand me. I don't have a lot of ROM Shocked so if it is a small code is better.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Mar 01, 2006 11:36 am     Reply with quote

If A is stored as a float it doesn't save any space to truncate it if you still keep it as a float. You could write your own multiplication routine that would only do the first few digits but I doubt you would save any space.

Perhapse a better question is whether you need floating point at all. If you are calculating a temperature of 27.3 degrees you may do all the math in integer hundredths of a degree to get 2730. Then when you print the result you just put a decimal point where it is needed using string manipulation. In my main product I measure the hull of ships in millimeters. I use a 24 bit intger format. If I calculate a ship is 203456 mm long I print the result as 203.456 meters without using floating point math at all..
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah
Guest







PostPosted: Thu Mar 02, 2006 6:03 am     Reply with quote

Worth adding here, that the compiler now has it's own ability to insert a decimal point, for output, and integer code, is both smaller, and faster than fp. Ideally of course, if you could 'work back', and not go float at all, since as it stands, there is the overhead of converting to integer. However as it stands:
Code:

int32 A32;
A32 = a*100;
A32 *= (int32)(b*100);
printf("%6.4w",A32);


Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group