Can I control the output format of type float? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Can I control the output format of type float?

Hi!

When I use write or writeln to output some float number on terminal or textfile, it usually print out the float with very long scientific notation. Can I just change the output format? such as keep only 3 significant digits.

Thank you!

Comments

  • earth_walkerearth_walker Posts: 184Member
    [b][red]This message was edited by earth_walker at 2003-7-1 11:31:16[/red][/b][hr]
    Hi! I find the routine FormatFloat.

    However, is there any way for me to make the positive number have the same length as its opposite negative number/
    for example, if we use the format string '0.000E+00' to 1234, the result will be '1.234E+03'. However, if use this format string to -1234, result will be '-1.234E+03', how can I make the result string of 1234 to ' 1.234E+03'?

    Thank you!



  • earth_walkerearth_walker Posts: 184Member
    For example, if I want all Integer output 4 digits, can I convert 28 to ' 28' instead of '28'?

    Thank you!

  • zibadianzibadian Posts: 6,349Member
    : For example, if I want all Integer output 4 digits, can I convert 28 to ' 28' instead of '28'?
    :
    : Thank you!
    :
    :
    The following code will work in both cases:
    [code]
    s := some number conversion;
    while Length(s) < SomeLength do
    s := ' ' + s;
    [/code]
    Thus in case of an integer it becomes:
    [code]
    s := IntToStr(28);
    while Length(s) < 4 do
    s := ' ' + s;
    [/code]
    If you want to have an output of 0028, you can also use the Format() statement:
    [code]
    s := Format('%.4d', [28]);
    [/code]
  • earth_walkerearth_walker Posts: 184Member
    Thank you!
Sign In or Register to comment.