Discussion:
how do i use the "Format %" ?
(too old to reply)
nek
2006-08-26 16:26:02 UTC
Permalink
DELPHI 7 (newbie)
--------


In my application I have to present several big numbers in editboxes and
print them on a printer.
The problem is that the numbers are huge and i want something more elegant.
Example : Instead using a big editbox for N=1234567890.1234 I want
something like 1.23E09 or even better 12.34E08. Get the picture ?
How can i do that using the "format %???" ? I have read the .hlp file
and it doesn't work out the way i want to.
Rob Kennedy
2006-08-26 16:54:22 UTC
Permalink
Post by nek
In my application I have to present several big numbers in editboxes and
print them on a printer.
The problem is that the numbers are huge and i want something more elegant.
Example : Instead using a big editbox for N=1234567890.1234 I want
something like 1.23E09 or even better 12.34E08. Get the picture ?
I don't think that latter format is a good idea, unless you're doing it
to get the same exponent for a series of related numbers. Normal
scientific notation always has a mantissa less than 10 and greater than
or equal to one. Engineering notation instead uses a mantissa less than
1000, but the exponent is always a multiple of three. Your value of
12.34e8 doesn't match either of those rules.

Is it your intention, in the latter format, to truncate the value or
round it down, rather than round it to the nearest value, which would be
12.35e8?
Post by nek
How can i do that using the "format %???" ? I have read the .hlp file
and it doesn't work out the way i want to.
If you're using the Format function, then the format specifier to use is
e. You want two digits after the decimal point, so the precision
specifier should be 2. The precision specifier comes after a period in
the format string:

%.2e

The exponent always has a sign and three digits, padded on the left with
zeros. If you really need no positive sign and only two digits, then you
can't use Format by itself. Perhaps you could simply use the Delete
function to remove the characters you don't want.

Or you could use the FormatFloat function. You want scientific notation
with a capital E, so use one of the E+ and E- codes. Since you don't
want the sign for positive exponents, use E-. You want two digits after
the decimal and two digits for the exponent, so use 0 instead of #:

0.00E-00

For your unnormalized form, try this:

00.00E-00
--
Rob
Loading...