View previous topic :: View next topic |
Author |
Message |
benedictkim
Joined: 14 Nov 2019 Posts: 11
|
float ??? |
Posted: Fri Feb 21, 2020 8:09 am |
|
|
Hi all.
Version IDE/PCB/PCM/PCH/PDC - 5.016.
MCU - dsPIC30F6014A
float curr_volt;
float cal_r_value;
float val = 0;
uint8_t ret_temper;
val = (float)adc_value;
fprintf(PLC, "V1:%1.2w\r\n", val);
=> V1: 11362959.36 ?????????????
val = adc_value;
fprintf(PLC, "V2:%1.2w\r\n", val);
=> V1: 11362959.36 ?????????????
In addition, in fprintf
fprintf (PLC, "V2:% 1.2f \ r \ n", val); ?????????
Repeats the board continuous reset.
Thank for your attention ! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: float ??? |
Posted: Fri Feb 21, 2020 8:41 am |
|
|
benedictkim wrote: |
Version 5.016 dsPIC30F6014A
|
From the CCS versions page:
5.031 Fixed a PIC24 bug in %w when used with signed numbers.
5.037 The PIC24 printf() %w no longer forces the leading zeros.
5.041 A problem with %w where if the digit after the '.' was 0, it did not output on the PIC24 is fixed.
5.044 Corrected a formatting issue in %W (%LU, %LD should not have been affected)
5.050 Fixed a bug when negative number were used with %W on 24 bit parts
http://www.ccsinfo.com/devices.php?page=versioninfo |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Feb 21, 2020 9:43 am |
|
|
this...
%1.2w
seems to say to me....
print a 1 digit number(0-255) with 2 decimal points.. Am I wrong ?
from the manual..
Unsigned int with decimal place inserted. Specify two numbers for n. The first is a total field width. The second is the desired number of decimal places.
I'm surprised the compiler doesn't report an error...
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Feb 21, 2020 12:36 pm |
|
|
The standard is to just overflow if the leading digit is not large enoough.
It's a common misunderstanding. Quite a few other languages specify
numeric output with the first digit being the numbers in front of the
decimal. C is one of the few where it is the field width instead.
%4.2w is the correct way to get n.nn |
|
|
|