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

signed 32 bit number with a decimal place?

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

signed 32 bit number with a decimal place?
PostPosted: Sun Jul 19, 2015 9:34 pm     Reply with quote

Hi All,

How do i print a signed 32 bit number with a decimal place?

Thanks,
G
_________________
CCS PCM 5.078 & CCS PCH 5.093
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 19, 2015 10:31 pm     Reply with quote

The CCS manual says %w is only for unsigned integers, but it appears to
work for signed. The program below has this output in MPLAB vs. 8.92
simulator:
Quote:
-12.345

Code:

#include <18F4620.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//===================================
void main()
{
signed int32 num = -12345;

printf("%5.3w \r", num);

while(TRUE);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19492

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 2:43 am     Reply with quote

It's one where they really should update the manual....

The function is very cleverly 'massively overloaded', and accepts int8, int16, int32, unsigned or signed, without demur. The impressive thing is that all appear to work OK.

It's been doing this for a long time now (there were some hiccups in some early V4 versions), but it 'does a lot more than it says on the tin'!. Smile
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 8:13 am     Reply with quote

That's odd... it was not working for me last night, thus my question.

I'll retry tonight and if all fails, I'll post a sample program.

I'm using PCH with the version on my signature.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Ttelmah



Joined: 11 Mar 2010
Posts: 19492

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 8:22 am     Reply with quote

It's vital that the number you pass is correctly typed.
It'll only accept the integer as signed, if it is typed as signed, as PCM_Programmer shows.

I checked right back to quite early V4 versions a while ago, and all worked OK.
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 2:35 pm     Reply with quote

Maybe more info is necessary.

My sensor returns a 32 bit int like: 2501 which i want to display as 25.01

It's a temperature sensor.


I've gotten it to display as 2501.00 but thats not really what I'm looking for.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 2:43 pm     Reply with quote

The program below shows 25.01 in MPLAB simulator with CCS vs. 5.047:
Quote:
25.01

Code:
#include <18F4620.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//===================================
void main()
{
signed int32 num = 2501;

printf("%4.2w \r", num);

while(TRUE);
}
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 7:56 pm     Reply with quote

Well that worked and now i feel stupid... because i tried it last night...

Thanks for your help, ive done the changes as suggested and its working as expected.


thanks!
_________________
CCS PCM 5.078 & CCS PCH 5.093
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Jul 20, 2015 8:10 pm     Reply with quote

There is nothing that fixes something faster than trying to show someone else what is broken Twisted Evil

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
Ttelmah



Joined: 11 Mar 2010
Posts: 19492

View user's profile Send private message

PostPosted: Tue Jul 21, 2015 12:15 am     Reply with quote

Very true.

It's often not even the actual 'showing', but the act of getting 'ready to show' makes you look again, and suddenly the answer becomes obvious. 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