Ada 编程/库/Ada.Text_IO.Editing
外观
此语言功能从 Ada 95 开始可用。
Ada.Text_IO.Editing 是 预定义语言环境 中的一个单元,自 Ada 95 以来一直存在。
此包用于从表示某些货币金额的数字生成和打印字符串。可以通过将 ""
作为参数传递来简单地避免包含货币。
表示 Ada.Text_IO.Editing 用法的示例。
with
Ada.Text_IO.Editing;procedure
Example_Eurosis
type
Euro_Price_Typeis
delta
0.01digits
6;package
Euros_IOis
new
Ada.Text_IO.Editing.Decimal_Output (Num => Euro_Price_Type, Default_Currency => "EUR ", Default_Fill => ' ', Default_Separator => ',', Default_Radix_Mark => '.'); A_Price :constant
Euro_Price_Type := 5873.26;begin
Ada.Text_IO.Put_Line ("Price with cents: "); -- We generate a string image and print it using Text_IO Ada.Text_IO.Put_Line (Euros_IO.Image (Item => A_Price, Pic => Ada.Text_IO.Editing.To_Picture ("#_###_###_##9.99"))); Ada.Text_IO.Put_Line ("Integer price: "); -- Let's use now the Put procedure from Euros_IO Euros_IO.Put (Item => A_Price, Pic => Ada.Text_IO.Editing.To_Picture ("#_###_###_##9"));end
Example_Euros;
Price with cents:
EUR 5,873.26
Integer price:
EUR 5,873
-- Standard Ada library specification -- Copyright (c) 2003-2018 Maxim Reznik <[email protected]> -- 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.Editingis
type
Pictureis
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 := '.';generic
type
Numis
delta
<>digits
<>; Default_Currency :in
String := Text_IO.Editing.Default_Currency; Default_Fill :in
Character := Text_IO.Editing.Default_Fill; Default_Separator :in
Character := Text_IO.Editing.Default_Separator; Default_Radix_Mark :in
Character := Text_IO.Editing.Default_Radix_Mark;package
Decimal_Outputis
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
Ada.Text_IO.Editing;
外部示例
[编辑源代码]- 在以下位置搜索
Ada.Text_IO.Editing
的 示例: Rosetta Code,GitHub (gists),任何 Alire 包 或 此维基教科书。 - 在以下位置搜索与
Ada.Text_IO.Editing
相关的 帖子: Stack Overflow,comp.lang.ada 或 任何与 Ada 相关的页面。
FSF GNAT
- 规范: a-teioed.ads
- 主体: a-teioed.adb
drake