Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Can I control the output format of type float? Posted by earth_walker on 1 Jul 2003 at 11:12 AM
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!
Report
Re: Can I control the output format of type float? Posted by earth_walker on 1 Jul 2003 at 11:22 AM
This message was edited by earth_walker at 2003-7-1 11:31:16

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!



Report
Can I also format the output of Integer? Posted by earth_walker on 1 Jul 2003 at 11:38 AM
For example, if I want all Integer output 4 digits, can I convert 28 to ' 28' instead of '28'?

Thank you!

Report
Re: Can I also format the output of Integer? Posted by zibadian on 1 Jul 2003 at 3:21 PM
: 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:
  s := some number conversion;
  while Length(s) < SomeLength do
    s := ' ' + s;

Thus in case of an integer it becomes:
  s := IntToStr(28);
  while Length(s) < 4 do
    s := ' ' + s;

If you want to have an output of 0028, you can also use the Format() statement:
  s := Format('%.4d', [28]);

Report
Re: Can I also format the output of Integer? Posted by earth_walker on 1 Jul 2003 at 5:39 PM
Thank you!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.