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

sprintf and number percision question?

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







sprintf and number percision question?
PostPosted: Wed Feb 05, 2003 6:50 am     Reply with quote

Hi,

I was wondering how to do the following, or if their is a better way?

char conversion[15];
char data[15];
float num;

num=12.34;
sprintf(conversion,"\%\%5.2f");
sprintf(data,conversion,num); //data gets "12.34"?

I could not get the above code to work. Basically I trying to display a number with a user selectable percision. That is the user could say I want 2 decimal places or 3. I thought the above code would be a good way to do this. Does someone have a better soultion?

Thanks
Trampas
___________________________
This message was ported from CCS's old forum
Original Post ID: 11297
Sherpa Doug
Guest







Re: sprintf and number percision question?
PostPosted: Wed Feb 05, 2003 12:00 pm     Reply with quote

:=Hi,
:=
:=I was wondering how to do the following, or if their is a better way?
:=
:=char conversion[15];
:=char data[15];
:=float num;
:=
:=num=12.34;
:=sprintf(conversion,"\%\%5.2f");
:=sprintf(data,conversion,num); //data gets "12.34"?
:=
:=I could not get the above code to work. Basically I trying to display a number with a user selectable percision. That is the user could say I want 2 decimal places or 3. I thought the above code would be a good way to do this. Does someone have a better soultion?
:=
:=Thanks
:=Trampas

I think the sprintf format is set at compile time. Either print a big format to a string and trim it from there, or select from multiple sprintf statements.

Its only an itty bitty PIC, you are asking a lot of it!

___________________________
This message was ported from CCS's old forum
Original Post ID: 11304
Trampas Stern
Guest







Re: sprintf and number percision question?
PostPosted: Wed Feb 05, 2003 7:28 pm     Reply with quote

Why are people always saying the PIC is small? I am using a 18F8720 which has 10MIPS and tons of code space.

I guess I will implement a switch/case statement which would take more code space and execution cycles than the sprintf, good thing the pic is not small...

Trampas

:=:=Hi,
:=:=
:=:=I was wondering how to do the following, or if their is a better way?
:=:=
:=:=char conversion[15];
:=:=char data[15];
:=:=float num;
:=:=
:=:=num=12.34;
:=:=sprintf(conversion,"\%\%5.2f");
:=:=sprintf(data,conversion,num); //data gets "12.34"?
:=:=
:=:=I could not get the above code to work. Basically I trying to display a number with a user selectable percision. That is the user could say I want 2 decimal places or 3. I thought the above code would be a good way to do this. Does someone have a better soultion?
:=:=
:=:=Thanks
:=:=Trampas
:=
:=I think the sprintf format is set at compile time. Either print a big format to a string and trim it from there, or select from multiple sprintf statements.
:=
:=Its only an itty bitty PIC, you are asking a lot of it!
:=
___________________________
This message was ported from CCS's old forum
Original Post ID: 11329
Sherpa Doug
Guest







Re: Itty bitty PIC?
PostPosted: Thu Feb 06, 2003 8:13 am     Reply with quote

:=Why are people always saying the PIC is small? I am using a 18F8720 which has 10MIPS and tons of code space.
:=

I guess it is the way I use PICs. I still use the 16C5X series of chips. Most of my C code fits in 512 bytes. My tiny programs are easy to debug. Only when I have to do a lot of human interaction do I need the bigger 2K chips. If I have logical operations that take more code I usually use multiple PICs.

My first paying PIC job was for a project I inherited when the lead engineer was fired. He was trying to use a 386 at 120MHz to do eight range calculations in assembly in real time, and failing. I put a 16C54 at 20MHz on each range with one 16C58 to collect the results from the 16C54s and packetize it for export to a PC. I am now doing ten ranges fine. The bottleneck is the RS232 port to the PC, but the next generation will use Ethernet instead.

Moral of the story: A pack of itty bitty PICs can sometimes out do a mighty X86.

___________________________
This message was ported from CCS's old forum
Original Post ID: 11353
Trampas Stern
Guest







Re: Itty bitty PIC?
PostPosted: Thu Feb 06, 2003 10:59 am     Reply with quote

My personal love the fact the PICs have everything, memory, flash, IOs, ADC all on the chip. I also have 4 PICs on my current design some small ones as Analog to Digital and then the 18F8720 to collect and provide user interfacing.

Thus their is a PIC soultion for every problem....

Trampas
___________________________
This message was ported from CCS's old forum
Original Post ID: 11361
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