Newsgroup: it.comp.programmare.win32
Titolo: ftow -- sara' chiedere troppo?

Ho un problema semplice, e fino a mezz'ora fa pensavo che avesse una
soluzione semplice: devo convertire un valore in virgola mobile (float o
double, ho facolta' di scelta) in una stringa unicode a due posizioni
decimali.
Finora ho trovato
char *_ecvt( double value, int count, int *dec, int *sign );
char *_fcvt( double value, int count, int *dec, int *sign );
char *_gcvt( double value, int digits, char *buffer );
*TUTTI* char.
Il compilatore, nello specifico, e' un evil Visual C (quindi sistema target
Win CE).
Devo arrendermi o esiste una funzione W equivalente alla _fcvt?
TIA,
*

 ha scritto nel messaggio
news:bmp3cs$p2h9j$1...@ID-68324.news.uni-berlin.de...

Io uso:
_TCHAR buffer [15];
_stprintf (buffer, _T("%.2f"), doublevar);
Ellebi

 posizioni decimali.
swprintf. Il float č %f e il double č %lf e la precisione si indica con 
%.<precisione>f. _snwprintf sarebbe piů sicura (permette di specificare 
le dimensioni del buffer), ma non č standard
-- 
  < 
http://www.reactos.com/
 >  Open source clone of Windows NT. Current
      Don't stand, REACT!      version 0.1.4. C, C++ and ASM developers
                               and beta testers are welcome!

swprintf. Il float č %f e il double č %lf 
Non dovrebbe essere cosě.  %f per le *printf č sia per i double che
per i float (c'č difatti promozione di tipi da float a double nel
passaggio dei parametri).  Contrariamente a quanto avviene, invece,
per le *scanf, in cui %f č per i float, %lf per i double e %Lf per i
long double.

> swprintf. Il float è %f e il double è %lf e la precisione si indica con 
Ottimo il tuo stile. Purtroppo l'ANSI lo ha un pò rovinato sullo
specificatore
l (elle) per le varie printf:
l (ell) 
Specifies that a following d, i, o, u, x, or X conversion specifier
applies to a
long int or unsigned long int argument; that a following n
conversion specifier applies to a pointer to a long int argument; that a
following c conversion specifier applies to a wint_t argument; that a
following s conversion specifier applies to a pointer to a wchar_t
argument; or has no effect on a following a, A, e, E, f, F, g, or G
conversion
specifier.
Rimane comunque corretto usare quel buon stile!
Saluti
JJ
-- 
Posted via Mailgate.ORG Server - 
http://www.Mailgate.ORG

 Non dovrebbe essere così
abbi pazienza, è l'età che avanza. Per la precisione:
"[...]
Each conversion specification is introduced by the '%' character [...], 
after which the following appear in sequence:
Zero or more flags (in any order), which modify the meaning of the 
conversion specification.
An optional minimum field width. [...]
An optional precision that gives [...] the number of digits to appear 
after the radix character for the a , A , e , E , f , and F conversion 
specifiers; the maximum number of significant digits for the g and G 
conversion specifiers [...]
An optional length modifier [...]
A conversion specifier character that indicates the type of conversion 
to be applied.
[...]
The flag characters and their meanings are:
[...]
#
Specifies that the value is to be converted to an alternative form. 
[...] For a , A , e , E , f , F , g , and G conversion specifiers, the 
result shall always contain a radix character, even if no digits follow 
the radix character. Without this flag, a radix character appears in 
the result of these conversions only if a digit follows it. For g and G 
conversion specifiers, trailing zeros shall not be removed from the 
result as they normally are. [...]
0
For d , i , o , u , x , X , a , A , e , E , f , F , g , and G 
conversion specifiers, leading zeros (following any indication of sign 
or base) are used to pad to the field width; no space padding is 
performed. If the '0' and '-' flags both appear, the '0' flag is 
ignored. [...]
[...]
The length modifiers and their meanings are:
[...]
l (ell)
[...] or has no effect on a following a , A , e , E , f , F , g , or G 
conversion specifier.
L
Specifies that a following a , A , e , E , f , F , g , or G conversion 
specifier applies to a long double argument.
[...]
The conversion specifiers and their meanings are:
[...]
f, F
The double argument shall be converted to decimal notation in the style 
"[-]ddd.ddd", where the number of digits after the radix character is 
equal to the precision specification. If the precision is missing, it 
shall be taken as 6; if the precision is explicitly zero and no '#' 
flag is present, no radix character shall appear. If a radix character 
appears, at least one digit appears before it. The low-order digit 
shall be rounded in an implementation-defined manner. 
A double argument representing an infinity shall be converted in one of 
the styles "[-]inf" or "[-]infinity" ; which style is implementation-
defined. A double argument representing a NaN shall be converted in one 
of the styles "[-]nan(n-char-sequence)" or "[-]nan" ; which style, and 
the meaning of any n-char-sequence, is implementation-defined. The F 
conversion specifier produces "INF" , "INFINITY" , or "NAN" instead of 
"inf" , "infinity" , or "nan" , respectively.
e, E
The double argument shall be converted in the style "[-]d.ddde±dd", 
where there is one digit before the radix character (which is non-zero 
if the argument is non-zero) and the number of digits after it is equal 
to the precision; if the precision is missing, it shall be taken as 6; 
if the precision is zero and no '#' flag is present, no radix character 
shall appear. The low-order digit shall be rounded in an 
implementation-defined manner. The E conversion specifier shall produce 
a number with 'E' instead of 'e' introducing the exponent. The exponent 
shall always contain at least two digits. If the value is zero, the 
exponent shall be zero. 
A double argument representing an infinity or NaN shall be converted in 
the style of an f or F conversion specifier.
g, G
The double argument shall be converted in the style f or e (or in the 
style F or E in the case of a G conversion specifier), with the 
precision specifying the number of significant digits. If an explicit 
precision is zero, it shall be taken as 1. The style used depends on 
the value converted; style e (or E ) shall be used only if the exponent 
resulting from such a conversion is less than -4 or greater than or 
equal to the precision. Trailing zeros shall be removed from the 
fractional portion of the result; a radix character shall appear only 
if it is followed by a digit or a '#' flag is present. 
A double argument representing an infinity or NaN shall be converted in 
the style of an f or F conversion specifier.
a, A
A double argument representing a floating-point number shall be 
converted in the style "[-]0xh.hhhhp±d", where there is one hexadecimal 
digit (which shall be non-zero if the argument is a normalized 
floating-point number and is otherwise unspecified) before the decimal-
point character and the number of hexadecimal digits after it is equal 
to the precision; if the precision is missing and FLT_RADIX is a power 
of 2, then the precision shall be sufficient for an exact 
representation of the value; if the precision is missing and FLT_RADIX 
is not a power of 2, then the precision shall be sufficient to 
distinguish values of type double, except that trailing zeros may be 
omitted; if the precision is zero and the '#' flag is not specified, no 
decimal-point character shall appear. The letters "abcdef" shall be 
used for a conversion and the letters "ABCDEF" for A conversion. The A 
conversion specifier produces a number with 'X' and 'P' instead of 'x' 
and 'p' . The exponent shall always contain at least one digit, and 
only as many more digits as necessary to represent the decimal exponent 
of 2. If the value is zero, the exponent shall be zero. 
A double argument representing an infinity or NaN shall be converted in 
the style of an f or F conversion specifier.
[...]"


Grazie a tutti, mi mancava la parte su come specificare la dimensione della
parte decimale :)
Ciaotutti,
*

abbi pazienza, č l'etŕ che avanza. Per la precisione:
144 righe di messaggio per dire che ho ragione ? ;-)