digitalmars.D.learn - Formatted Output: Exact number of Decimal Places
- Q. Schroll (17/17) May 16 2016 Lets say I want to print a table with floats. How can it be
- Marco Leise (5/22) May 16 2016 Use %#6.3f to get the above output.
- Andrew Chamberlain (13/30) May 16 2016 I have this one:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (3/20) May 16 2016 Also try "%.3g".
Lets say I want to print a table with floats. How can it be formatted like that: | 2.4 | | 12.2 | | 8.131 | | 17.44 | Also acceptable is | 2.400 | | 12.200 | | 8.131 | | 17.440 | but not | 02.4 | | 12.2 | | 08.131 | | 17.44 | or any other solutions with leading zeros.
May 16 2016
Am Mon, 16 May 2016 20:24:51 +0000 schrieb Q. Schroll <qs.il.paperinik gmail.com>:Lets say I want to print a table with floats. How can it be formatted like that: | 2.4 | | 12.2 | | 8.131 | | 17.44 | Also acceptable is | 2.400 | | 12.200 | | 8.131 | | 17.440 |but not | 02.4 | | 12.2 | | 08.131 | | 17.44 | or any other solutions with leading zeros.-- Marco
May 16 2016
On Monday, 16 May 2016 at 20:24:51 UTC, Q. Schroll wrote:Lets say I want to print a table with floats. How can it be formatted like that: | 2.4 | | 12.2 | | 8.131 | | 17.44 | Also acceptable is | 2.400 | | 12.200 | | 8.131 | | 17.440 | but not | 02.4 | | 12.2 | | 08.131 | | 17.44 | or any other solutions with leading zeros.I have this one: ---- import std.stdio; import std.string, std.algorithm, std.format; void main(string[] args) { [2.4, 12.2, 8.131, 17.44].each!(a => format("%.3f", a) .rightJustify(6).center(8).center(10,'|').writeln); } ---- But only works if fractional and integral part are both up to 3 digits.
May 16 2016
On 05/16/2016 01:24 PM, Q. Schroll wrote:Lets say I want to print a table with floats. How can it be formatted like that: | 2.4 | | 12.2 | | 8.131 | | 17.44 | Also acceptable is | 2.400 | | 12.200 | | 8.131 | | 17.440 | but not | 02.4 | | 12.2 | | 08.131 | | 17.44 | or any other solutions with leading zeros.Also try "%.3g". Ali
May 16 2016