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 CCS Technical Support

Float value into bytes

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



Joined: 09 Mar 2013
Posts: 20

View user's profile Send private message

Float value into bytes
PostPosted: Tue Apr 09, 2013 4:25 am     Reply with quote

Hello everybody!
I try to divide a float value like this
Code:
float temperature;
temperature = 23.5;
dec = int(temperature / 10);// must be 2

I want to have int "2" in dec variable.
When i compile, i get an error
Quote:
A numeric expression must appear here

How can i split float value into separate bytes?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Apr 09, 2013 4:55 am     Reply with quote

Your syntax is wrong. Missing brackets:

Code:

float temperature;
temperature = 23.5;
dec = (int)(temperature / 10);// must be 2


You are telling it to call a function called 'int', not convert the result to an int....

Best Wishes
pavelustinov



Joined: 09 Mar 2013
Posts: 20

View user's profile Send private message

PostPosted: Tue Apr 09, 2013 6:09 am     Reply with quote

Ttelmah wrote:
Your syntax is wrong. Missing brackets:

You are telling it to call a function called 'int', not convert the result to an int....

Best Wishes


Thank you very much.
I have one more question.
I need convert to string, ASCII string
Code:
dec = (int)(temperature / 10);


P.S. I found answer, thanks to all
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