You are here: Start » Basic » String » FormatDoubleToString
FormatDoubleToString
Header: | STD.h |
---|---|
Namespace: | avl |
Creates a string from a double number using a proper format.
Applications: Useful for preparing a number for display or communication with specific number of fractional digits, sign etc.
Syntax
void avl::FormatDoubleToString ( double inDouble, const int inIntegerDigitCount, const int inFractionalDigitCount, const atl::String& inDecimalMark, const atl::String& inTrailingCharacter, const bool inForceSignPrinting, const atl::String& inSuffix, atl::String& outString )
Parameters
Name | Type | Range | Default | Description | |
---|---|---|---|---|---|
inDouble | double | Input real | |||
inIntegerDigitCount | const int | 0 - 1000 | How many characters the integer part of the input real should have at least | ||
inFractionalDigitCount | const int | 0 - 100 | 3 | How many characters the fractional part of the input real should have | |
inDecimalMark | const String& | \".\" | The symbol used to separate the integer part from the fractional part of the number | ||
inTrailingCharacter | const String& | \"0\" | Defines the trailing character | ||
inForceSignPrinting | const bool | False | Forces printing the sign of the number even if the number is positive | ||
inSuffix | const String& | \"\" | Defines a suffix. Generally it is an unit of value (e.g. mm) | ||
outString | String& | Output string |
Examples
inDouble = 2.7182818284590452 inIntegerDigitCount = 2 inFractionalDigitCount = 2 inDecimalMark = "," inTrailingCharacter = "0" inForceSignPrinting = False inSuffix = "..." |
outString = "02,72..." |
In the first example desired integer digit count equals 2 as entered in inIntegerDigitCount, so the filter attaches character in inTrailingCharacter (zero)
at the beginning of the result outString. Decimal mark is set as a comma and the number of fractional digits as 2.
The result string ends with ellipsis defined in inSuffix and the result is "02,72...".
Note that the second digit was rounded up to "2" due to the succeeding digit.
inDouble = 77 inIntegerDigitCount = 1 inFractionalDigitCount = 1 inDecimalMark = "." inTrailingCharacter = "#" inForceSignPrinting = True inSuffix = "°" |
outString = "+77.0°" |
The second example demonstrates formatting with one integer digit and one fractional. Note that the integer part of the formatted number is less
than the value, but it doesn't affect to this part (unlike fractional part which can cuts off excessing digits).
Trailing character (#) doesn't affect to anything, because desired integer digit count described by inIntegerDigitCount is one
(the same effect would be for zero).
Remarks
Errors
List of possible exceptions:
Error type | Description |
---|---|
DomainError | inDecimalMark has to be a single character in FormatDoubleToString. |
DomainError | inTrailingCharacter has to be a single character in FormatDoubleToString. |
See Also
- FormatRealToString – Creates a string from a real number using a proper format.
- FormatIntegerToString – Creates a string from an integer number using a proper format.
- FormatString – Creates a string according to the given format and data.