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

My math operators, are not working as i want

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



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

My math operators, are not working as i want
PostPosted: Tue Mar 06, 2012 1:07 pm     Reply with quote

Code:

Double conta = 100 * 0.0512;
printf("%ld \r\n",conta);


Result expected = 5.12

Result i get = 9089
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 1:18 pm     Reply with quote

Try this

Float conta = 100 * 0.0512;
printf("%2.2f \r\n",conta);
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 1:19 pm     Reply with quote

I believe you are printing it as if it was an integer. Look at the formats for printf().
_________________
The search for better is endless. Instead simply find very good and get the job done.
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 1:27 pm     Reply with quote

if i change "conta" to float, it works curt2go

Isnt it supossed to work with double too?
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 1:41 pm     Reply with quote

Double is not used by CCS...

C Standard Type
Default Type

short
int1

char
unsigned int8

int
int8

long
int16

long long
int32

float
float32

Hope that helps..
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 1:44 pm     Reply with quote

C-standard type specifier for double is %g not %d. It's listed as "rounded decimal" float format in the CCS C manual, however.

Quote:
Double is not used by CCS...

Double is supported in PCD.
Chaud



Joined: 11 Jan 2012
Posts: 39

View user's profile Send private message

PostPosted: Tue Mar 06, 2012 1:59 pm     Reply with quote

Ok i get it, thanks for you help Smile
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