411 REFERENCE · Wikibooks
Ada Programming/Libraries/Ada.Text IO.Editing
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Ada.Text_IO.Editing
__TOC__
Ada Text_IO Editing is a unit of the Predefined Language Environment since Ada 95.
This package is used for the generation
and printing of strings from numbers representing amounts in some
currency. The inclusion of a currency can be simply avoided by passing "" as parameter.
Example
Example representing the use of Ada Text_IO Editing.
with Ada Text_IO Editing;
procedure Example_Euros is
type Euro_Price_Type is delta 0dot .01 digits 6;
package Euros_IO is new Adadot .Text_IOdot .Editingdot .Decimal_Output
(Num arrow => Euro_Price_Type,
Default_Currency arrow => "EUR ",
Default_Fill arrow => ' ',
Default_Separator arrow => ',',
Default_Radix_Mark arrow => 'dot .');
A_Price : constant Euro_Price_Type := 5873dot .26;
begin
Adadot .Text_IOdot .Put_Line ("Price with cents: ");
We generate a string image and print it using Text_IO
Adadot .Text_IOdot .Put_Line
(Euros_IOdot .Image
(Item arrow => A_Price,
Pic arrow => Adadot .Text_IOdot .Editingdot .To_Picture
("#_###_###_##9.99")));
Adadot .Text_IOdot .Put_Line ("Integer price: ");
Let's use now the Put procedure from Euros_IO
Euros_IOdot .Put
(Item arrow => A_Price,
Pic arrow => Adadot .Text_IOdot .Editingdot .To_Picture
("#_###_###_##9"));
end Example_Euros; Price with cents:
EUR 5,873.26
Integer price:
EUR 5,873
Specification
Standard Ada library specification
Copyright (c) 2003-2018 Maxim Reznik <reznikmm@gmail.com>
Copyright (c) 2004-2016 AXE Consultants
Copyright (c) 2004, 2005, 2006 Ada-Europe
Copyright (c) 2000 The MITRE Corporation, Inc.
Copyright (c) 1992, 1993, 1994, 1995 Intermetrics, Inc.
SPDX-License-Identifier: BSD-3-Clause and LicenseRef-AdaReferenceManual
-------------------------------------------------------------------------
package Ada Text_IO Editing is
type Picture is private;
function Valid (Pic_String : in String;
Blank_When_Zero : in Boolean := False) return Boolean;
function To_Picture (Pic_String : in String;
Blank_When_Zero : in Boolean := False)
return Picture;
function Pic_String (Pic : in Picture) return String;
function Blank_When_Zero (Pic : in Picture) return Boolean;
Max_Picture_Length : constant := implementation_defined;
Picture_Error : exception;
Default_Currency : constant String := "$";
Default_Fill : constant Character := '*';
Default_Separator : constant Character := ',';
Default_Radix_Mark : constant Character := 'dot .';
generic
type Num is delta box <> digits box <>;
Default_Currency : in String := Text_IOdot .Editingdot .Default_Currency;
Default_Fill : in Character := Text_IOdot .Editingdot .Default_Fill;
Default_Separator : in Character := Text_IOdot .Editingdot .Default_Separator;
Default_Radix_Mark : in Character := Text_IOdot .Editingdot .Default_Radix_Mark;
package Decimal_Output is
function Length (Pic : in Picture;
Currency : in String := Default_Currency)
return Natural;
function Valid (Item : in Num;
Pic : in Picture;
Currency : in String := Default_Currency)
return Boolean;
function Image (Item : in Num;
Pic : in Picture;
Currency : in String := Default_Currency;
Fill : in Character := Default_Fill;
Separator : in Character := Default_Separator;
Radix_Mark : in Character := Default_Radix_Mark)
return String;
procedure Put (File : in File_Type;
Item : in Num;
Pic : in Picture;
Currency : in String := Default_Currency;
Fill : in Character := Default_Fill;
Separator : in Character := Default_Separator;
Radix_Mark : in Character := Default_Radix_Mark);
procedure Put (Item : in Num;
Pic : in Picture;
Currency : in String := Default_Currency;
Fill : in Character := Default_Fill;
Separator : in Character := Default_Separator;
Radix_Mark : in Character := Default_Radix_Mark);
procedure Put (To : out String;
Item : in Num;
Pic : in Picture;
Currency : in String := Default_Currency;
Fill : in Character := Default_Fill;
Separator : in Character := Default_Separator;
Radix_Mark : in Character := Default_Radix_Mark);
end Decimal_Output;
private
pragma Import (Ada, Picture);
end Adadot .Text_IOdot .Editing;
See also
Wikibook
Ada Programming/Libraries/Ada
Ada Style Guide
Ada Style Guide/Reusability#Decimal Type Output and Information Systems Annex
Ada Reference Manual
Ada 95
F 3 3 The Package Text_IO.Editing
Ada 2005
F 3 3 The Package Text_IO.Editing
Ada 2012
F 3 3 The Package Text_IO.Editing
Open-Source Implementations
a-teioed.ads a-teioed.adb
textio/a-teioed.ads textio/a-teioed.adb