Re: how do i use the "Format %" ?



nek wrote:
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?

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
.



Relevant Pages

  • Re: Rounding off double precision
    ... of digits for list directed output. ... specify how many digits to print out for an * format. ... are printed with an E exponent when you use the E edit descriptor. ...
    (comp.lang.fortran)
  • Re: Decimal Floating Point (was Re: why still use C?)
    ... >>three digits stored into 10 bits, ... The memory format is only slightly less efficient than ... >>the desired exponent range. ... > be a decimal format, that would be a base 1000 format. ...
    (comp.lang.c)
  • Re: How to get the exponent of a real number?
    ... implicit none ... exponent in base 2. ... If your desire is to get the exponent as formatted with E format, you would need to use internal E format write to make a character string, then search for the digits following the E. ...
    (comp.lang.fortran)
  • Re: Rounding off double precision
    ... which is about the expected accuracy for double precision. ... specify how many digits to print out for an * format. ... are printed with an E exponent when you use the E edit descriptor. ...
    (comp.lang.fortran)
  • Re: Format function help
    ... >> I need to format a TAutoIncField to a two place string. ... > is converted to a string of decimal digits. ... > contains a precision specifier, ...
    (borland.public.delphi.language.objectpascal)