Autor Tema: Sentencia printf con floats  (Leído 1901 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado franda

  • PIC10
  • *
  • Mensajes: 32
Sentencia printf con floats
« 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

Desconectado Arlequin

  • Colaborador
  • PIC18
  • *****
  • Mensajes: 340
RE: Sentencia printf con floats
« Respuesta #1 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.
¡¡Ex - c3poa!!            ---       Collapsing New People

Desconectado pocher

  • Moderador Local
  • DsPIC30
  • *****
  • Mensajes: 2569
RE: Sentencia printf con floats
« Respuesta #2 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.


 

anything