![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Kova
Joined: 06 May 2007 Posts: 35
|
Float on USB |
Posted: Wed May 23, 2007 1:48 am |
|
|
Hi,
sorry for my english
I have this code for send a float value to usb port:
printf(usb_cdc_putc,"%3.1f\n", temperature);
On the terminal I receive this value (for example):
29.1
It's possible to send the float rappresentation with the comma and not with the point? (for example):
29,1
Thanks for the help
Bye |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Wed May 23, 2007 2:41 am |
|
|
Really, you would have to do it yourself.
Use 'sprintf', to send the data to a string, and then use the string functions to look for '.', and change this to the required ',', then print the string to the output.
A 'silly' (but effective) way of doing this without having to fiddle like this, is:
Code: |
#define DECIMAL_SEPARATOR (',')
void send_char_filtered(int8 chr) {
if (chr=='.') chr=DECIMAL_SEPARATOR;
usb_cdc_putc(chr);
}
|
Then:
Code: |
printf(send_char_filtered,"%3.1f\n", temperature);
|
The neat thing here, is that if you want to use '.', you only need to have the line:
#define DECIMAL_SEPARATOR ('.')
and the same code will then print using the '.', while with the separator defined as ',', these will be substituted.
The obvious 'limitiation', is that you should only use this output routine for numeric values, otherwise full stops in text, will also be substituted...
I use this approach, in a couple of instruments, where a language selection is made during initialisation, and the numeric outputs all route through a filter like this.
The setup for localisation is now present in the compiler, and with the move towards ANSI compliance, a fully operational 'locale' ability will probably appear, but at present, 'DIY', is the way to go.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Kova
Joined: 06 May 2007 Posts: 35
|
|
Posted: Wed May 23, 2007 8:35 am |
|
|
Thanks a lot ;) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|