Stay organized with collections Save and categorize content based on your preferences.
class ScientificNumberFormatter
A formatter that formats numbers in user-friendly scientific notation. ScientificNumberFormatter instances are immutable and thread-safe. Sample code:
ULocale en = new ULocale("en"); ScientificNumberFormatter fmt = ScientificNumberFormatter.getMarkupInstance( en, "<sup>", "</sup>");
// Output: "1.23456×10<sup>-78</sup>" System.out.println(fmt.format(1.23456e-78));
Summary
Public methods |
String! | Formats a number |
static ScientificNumberFormatter! | Gets a ScientificNumberFormatter instance that uses markup for exponents. |
static ScientificNumberFormatter! | Gets a ScientificNumberFormatter instance that uses markup for exponents for this locale. |
static ScientificNumberFormatter! | Gets a ScientificNumberFormatter instance that uses superscript characters for exponents. |
static ScientificNumberFormatter! | Gets a ScientificNumberFormatter instance that uses superscript characters for exponents for this locale. |
Public methods
fun format(number: Any!): String!
Formats a number
Parameters |
number | Any!: Can be a double, int, Number or anything that DecimalFormat#format(Object) accepts. |
Return |
String! | the formatted string. |
getMarkupInstance
static fun getMarkupInstance(
df: DecimalFormat!,
beginMarkup: String!,
endMarkup: String!
): ScientificNumberFormatter!
Gets a ScientificNumberFormatter instance that uses markup for exponents.
Parameters |
df | DecimalFormat!: The DecimalFormat must be configured for scientific notation. Caller may safely change df after this call as this method clones it when creating the ScientificNumberFormatter. |
beginMarkup | String!: the markup to start superscript e.g <sup> |
endMarkup | String!: the markup to end superscript e.g </sup> |
getMarkupInstance
static fun getMarkupInstance(
locale: ULocale!,
beginMarkup: String!,
endMarkup: String!
): ScientificNumberFormatter!
Gets a ScientificNumberFormatter instance that uses markup for exponents for this locale.
Parameters |
locale | ULocale!: The locale |
beginMarkup | String!: the markup to start superscript e.g <sup> |
endMarkup | String!: the markup to end superscript e.g </sup> |
getSuperscriptInstance
static fun getSuperscriptInstance(df: DecimalFormat!): ScientificNumberFormatter!
Gets a ScientificNumberFormatter instance that uses superscript characters for exponents.
Parameters |
df | DecimalFormat!: The DecimalFormat must be configured for scientific notation. Caller may safely change df after this call as this method clones it when creating the ScientificNumberFormatter. |
getSuperscriptInstance
static fun getSuperscriptInstance(locale: ULocale!): ScientificNumberFormatter!
Gets a ScientificNumberFormatter instance that uses superscript characters for exponents for this locale.
Parameters |
locale | ULocale!: The locale |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[]]