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 support@ccsinfo.com

float ???

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



Joined: 14 Nov 2019
Posts: 11

View user's profile Send private message

float ???
PostPosted: Fri Feb 21, 2020 8:09 am     Reply with quote

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

View user's profile Send private message

Re: float ???
PostPosted: Fri Feb 21, 2020 8:41 am     Reply with quote

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: 9205
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 21, 2020 9:43 am     Reply with quote

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: 19451

View user's profile Send private message

PostPosted: Fri Feb 21, 2020 12:36 pm     Reply with quote

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
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