indexing
description: "Formatter for non-integral numbers"
names: format_double
class interface
FORMAT_DOUBLE
create
make (w, d: INTEGER)
require
reasonable_field: w >= 1;
reasonable_decimals: d <= w
ensure
blank_fill: fill_character = ' ';
show_sign_negative: show_sign_negative;
no_separator: no_separator;
width_set: width = w;
right_justified: right_justified;
leading_sign: leading_sign;
decimals_set: decimals = d;
decimal_point: decimal = '.'
feature -- Initialization
make (w, d: INTEGER)
require
reasonable_field: w >= 1;
reasonable_decimals: d <= w
ensure
blank_fill: fill_character = ' ';
show_sign_negative: show_sign_negative;
no_separator: no_separator;
width_set: width = w;
right_justified: right_justified;
leading_sign: leading_sign;
decimals_set: decimals = d;
decimal_point: decimal = '.'
set_defaults (w: INTEGER)
-- (from FORMAT_INTEGER)
require -- from FORMAT_INTEGER
reasonable_field: w >= 1
ensure -- from FORMAT_INTEGER
blank_fill: fill_character = ' ';
show_sign_negative: show_sign_negative;
no_separator: no_separator;
width_set: width = w;
right_justified: right_justified;
leading_sign: leading_sign
feature -- Access
after_decimal_separate: BOOLEAN
-- Use separators after the decimal?
bracketted_negative: BOOLEAN
-- Enclose negative numbers in brackets?
-- (from FORMAT_INTEGER)
decimal: CHARACTER
-- What is used for the decimal
decimals: INTEGER
-- Number of digits after the decimal point.
fill_character: CHARACTER
-- Padding character.
-- (from FORMAT_INTEGER)
justification: INTEGER
-- Where in the field the format goes.
-- (from FORMAT_INTEGER)
separator: CHARACTER
-- Separator between 1000's of numbers.
-- (from FORMAT_INTEGER)
sign_format: INTEGER
-- How the sign is formatted.
-- (from FORMAT_INTEGER)
sign_string: STRING
-- Formatting details for the sign.
-- (from FORMAT_INTEGER)
trailing_sign: BOOLEAN
-- Is the sign at the end?
-- (from FORMAT_INTEGER)
width: INTEGER
-- Width of the field.
-- (from FORMAT_INTEGER)
zero_not_shown: BOOLEAN
-- Show 0.5 as .5 or 0.5?
feature -- Status report
centered: BOOLEAN
-- Are numbers to be formatted centered?
-- (from FORMAT_INTEGER)
ignore_sign: BOOLEAN
-- Ignore the sign of a number?
-- (from FORMAT_INTEGER)
leading_sign: BOOLEAN
-- Is the sign leading?
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
Result = not trailing_sign
left_justified: BOOLEAN
-- Are numbers to be formatted with spaces on the right?
-- (from FORMAT_INTEGER)
no_separator: BOOLEAN
-- Is there a separator?
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
Result = (separator = '%U')
not_justified: BOOLEAN
-- Are numbers to be formatted in smallest string possible
-- (from FORMAT_INTEGER)
right_justified: BOOLEAN
-- Are numbers to be formatted with spaces on the left?
-- (from FORMAT_INTEGER)
show_sign: BOOLEAN
-- Are numbers to show sign whether positive or negative?
-- (from FORMAT_INTEGER)
show_sign_negative: BOOLEAN
-- Are numbers to show sign only when negative?
-- (from FORMAT_INTEGER)
show_sign_positive: BOOLEAN
-- Are numbers to show sign only when positive?
-- (from FORMAT_INTEGER)
feature -- Status setting
asterisk_fill
-- Fill numbers with asterisks.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
fill_character = '*'
blank_fill
-- Fill numbers with blanks.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
fill_character = ' '
bracket_negative
-- Bracket negative numbers.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
bracketted_negative
center_justify
-- Put padding on right and left
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
centered
comma_decimal
-- Use , as the decimal point.
ensure
decimal = ','
comma_separate
-- Set the separator to be comma.
ensure -- from FORMAT_INTEGER
separator = ','
ensure then
after_decimal_separate
dollar_fill
-- Fill numbers with dollars.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
fill_character = '$'
dot_separate
-- Set separator to period.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
separator = '.'
hide_zero
-- Show 0.5 as .5 .
ensure
zero_not_shown
left_justify
--Put padding on right
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
left_justified
no_justify
-- Always return the smallest string possible
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
not_justified
no_separate_after_decimal
-- Do not use separators after the decimal.
ensure
not after_decimal_separate
point_decimal
-- Use . as the decimal point.
ensure
decimal = '.'
remove_separator
-- Remove the separator.
ensure -- from FORMAT_INTEGER
separator = '%U'
ensure then
not after_decimal_separate
right_justify
-- Put padding on left
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
right_justified
separate_after_decimal
-- Use separators after the decimal.
ensure
after_decimal_separate
set_decimals (d: INTEGER)
-- d decimals to be displayed.
require
d <= width
ensure
decimals = d
set_fill (c: CHARACTER)
-- Fill numbers with c
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
fill_character = c
set_separator (c: CHARACTER)
-- Set the separator to c
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
separator = c
set_sign (s: STRING)
-- Set sign values for positive, zero, negative
-- All values must be the same length.
-- Stored as negative, zero, positive.
-- (from FORMAT_INTEGER)
require -- from FORMAT_INTEGER
s /= void;
s.count >= 3;
s.count \\ 3 = 0
ensure -- from FORMAT_INTEGER
sign_string.is_equal (s)
set_width (w: INTEGER)
-- Set width to w
-- (from FORMAT_INTEGER)
require -- from FORMAT_INTEGER
wide_enough: w >= 1
ensure -- from FORMAT_INTEGER
width = w
show_zero
-- Show 0.5 as 0.5 .
ensure
not zero_not_shown
sign_cr_dr
-- Set sign for CR/DR
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
sign_string.is_equal ("CR DR")
sign_dr_cr
-- Set sign for DR/CR
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
sign_string.is_equal ("DR CR")
sign_floating_dollar
-- Set sign for floating dollar.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
sign_string.is_equal ("$$$")
sign_floating_dollar_signed
-- Set sign for floating dollar include sign.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
sign_string.is_equal ("-$ $+$")
sign_ignore
-- Do not show sign.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
ignore_sign
sign_leading
-- Set the sign to lead
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
leading_sign
sign_negative_only
-- Show sign for negative numbers only.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
show_sign_negative
sign_normal
-- Set sign for - and +.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
sign_string.is_equal ("- +")
sign_positive_only
-- Show sign for positive numbers only.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
show_sign_positive
sign_show
-- Show sign for all numbers.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
show_sign
sign_trailing
-- Set the sign to trail
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
trailing_sign
unbracket_negative
-- Do not bracket negative numbers.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
not bracketted_negative
underscore_separate
-- Set the separator to be underscore.
ensure -- from FORMAT_INTEGER
separator = '_'
ensure then
after_decimal_separate
zero_fill
-- Fill numbers with zeros.
-- (from FORMAT_INTEGER)
ensure -- from FORMAT_INTEGER
fill_character = '0'
feature -- Conversion
formatted (d: DOUBLE): STRING
-- Format d.
ensure
exists: Result /= void;
correct_width: Result.count >= width
invariant
-- from GENERAL
reflexive_equality: standard_is_equal (Current);
reflexive_conformance: conforms_to (Current);
separate_all: no_separator implies not after_decimal_separate;
-- from FORMAT_INTEGER
sign_string_constraint: sign_string /= void;
wide_enough: width >= 1;
end -- class FORMAT_DOUBLE