View previous topic :: View next topic |
Author |
Message |
Chaud
Joined: 11 Jan 2012 Posts: 39
|
My math operators, are not working as i want |
Posted: Tue Mar 06, 2012 1:07 pm |
|
|
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
|
|
Posted: Tue Mar 06, 2012 1:18 pm |
|
|
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
|
|
Posted: Tue Mar 06, 2012 1:19 pm |
|
|
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
|
|
Posted: Tue Mar 06, 2012 1:27 pm |
|
|
if i change "conta" to float, it works curt2go
Isnt it supossed to work with double too? |
|
|
curt2go
Joined: 21 Nov 2003 Posts: 200
|
|
Posted: Tue Mar 06, 2012 1:41 pm |
|
|
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
|
|
Posted: Tue Mar 06, 2012 1:44 pm |
|
|
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
|
|
Posted: Tue Mar 06, 2012 1:59 pm |
|
|
Ok i get it, thanks for you help |
|
|
|