TODOPIC

Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: franda en 16 de Enero de 2006, 06:23:00

Título: Sentencia printf con floats
Publicado por: franda en 16 de Enero de 2006, 06:23:00
Hola.

Con la sentencia printf y teniendo que representar un número float ¿cuantos dígitos de parte entera y cuantos dígitos de parte decimal como se máximo se pueden representar?

Gracias
Título: RE: Sentencia printf con floats
Publicado por: Arlequin en 30 de Enero de 2006, 01:18:00
Si no me equivoco, 99 dígitos máximos en total y 9 dígitos máx para decimales, con lo que la parte entera máx sería de 90. (%99.9).

Por lo que se a mayor valor da error el compilador.
Título: RE: Sentencia printf con floats
Publicado por: pocher en 30 de Enero de 2006, 03:42:00
En la versión del manual de Febrero 2005 salía en printf que:

Format:

The format takes the generic form %wt. n is optional and may be 1-9 to specify how many characters are to be outputted, or 01-09 to indicate leading zeros, or 1.1 to 9.9 for floating point. t is the type and may be one of the following:

c  Character
 
s  String or character
 
u  Unsigned int

x  Hex int (lower case)
 
X  Hex int (upper case)
 
d  Signed int

e  Float in exponential format

f  Float

Lx  Hex long int (lower case)
 
LX  Hex long int (upper case)
 
Lu  Long unsigned int
 
Ld  Long signed int
 
% Just a %

(Cambian también algunas definiciones, que he aprovechado en el copiar --> pegar)

En el manual de Noviembre 2005 aparecen los cambios:

The format takes the generic form %nt. n is optional and may be 1-9 to specify how many characters are to be outputted, or 01-09 to indicate leading zeros, or 1.1 to 9.9 for floating point and %w output. t is the type and may be one of the following:

c  Character
 
s  String or character
 
u  Unsigned int
 
d  Signed int
 
Lu  Long unsigned int
 
Ld  Long signed int
 
x  Hex int (lower case)
 
X  Hex int (upper case)
 
Lx  Hex long int (lower case)
 
LX  Hex long int (upper case)
 
f  Float with truncated decimal  
 
g  Float with rounded decimal
 
e  Float in exponential format
 
w  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.
 

Yo entiendo que 1.1 to 9.9 for floating point significa 9 números máximo para la parte entera y 9 decimales máximo.

De todas formas támpoco lo tengo muy claro.