All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.meta.FormattingDocumentation Maven / Gradle / Ivy

package io.sphere.sdk.meta;

import org.javamoney.moneta.format.CurrencyStyle;
import org.javamoney.moneta.function.MonetaryUtil;

import java.time.format.DateTimeFormatter;

/**
 *
 * 

Temporal Data

* *

* *

Do not use {@link java.text.SimpleDateFormat}, it does not work with all temporal data types of the SDK:

* * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#doNotUseSimpleDateFormat()} * * Use {@link java.time.LocalDate#format(DateTimeFormatter)} with {@link DateTimeFormatter} instead: * * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#formatLocalDate()} * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#formatLocalTime()} * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#formatZonedDateTime()} * * *

Monetary Data

* * The SDK has a dependency to Moneta, the reference implementation for JSR 354 - Currency and Money. * We suggest to read the Moneta Userguide. * *

Creating MonetaryAmount values

* * The following example shows different ways to create the same money representation: * * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#createMoney()} * *

Formatting MonetaryAmount values

* *

For formatting you can just get a formatter per locale.

*

Example for Germany:

* * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#formatMoneyByGermanLocale()} * *

Example for the USA:

* * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#formatMoneyByUsLocale()} * *

You can also use the locale and force to use the currency symbol instead of the currency code:

* {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#formatMoneyCustom()} * *

If that is not flexible enough you can specify a pattern:

* * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#formatMoneyCustom3()} * *

¤ is the currency sign which can be formatted with the styles {@link CurrencyStyle#CODE}, {@link CurrencyStyle#NAME}, {@link CurrencyStyle#NUMERIC_CODE} and {@link CurrencyStyle#SYMBOL}.

* *

Obtain the cent amounts

* * Use {@link MonetaryUtil#minorUnits()} to get the whole amount as cents: * * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#getAmountInCents()} * * Use {@link MonetaryUtil#minorPart()} and {@link MonetaryUtil#minorUnits()} to get the minor unit (cent) part: * * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#getCents()} * *

Obtain the smooth amount

* * Use {@link MonetaryUtil#majorUnits()} to get the smooth amount: * * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#getMajorUnitAmount()} * *

Sorting MonetaryAmount values

* *

By the amount:

* {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#moneySortByAmount()} * *

By the currency and the amount:

* * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#moneySortByCurrencyAndAmount()} * *

Rounding MonetaryAmount values

* *

See JavaMoney Moneta User Guide - Rounding.

* * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#roundMoneyDownExample()} * {@include.example io.sphere.sdk.meta.FormattingDocumentationTest#roundMoneyUpExample()} * * */ public class FormattingDocumentation { private FormattingDocumentation() { } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy