MoneyFormatterBuilder Class
Definition
Fluently composes a MoneyFormatter for complex formatting scenarios.
public sealed class MoneyFormatterBuilder
- Inheritance
-
MoneyFormatterBuilder
- Inherited Members
- Extension Methods
Remarks
Use the builder to capture a reusable display policy once instead of scattering format strings through the code base; the built MoneyFormatter is immutable and safe to share.
using System.Globalization;
using Bodu.Financial;
MoneyFormatter formatter = new MoneyFormatterBuilder()
.WithEnglishName()
.WithCulture(new CultureInfo("en-US"))
.Build();
var text = formatter.Format(Money.From(1234.56m, CurrencyCode.USD)); // "1,234.56 US Dollar"
Constructors
MoneyFormatterBuilder()
public MoneyFormatterBuilder()
Methods
Build()
Builds the configured MoneyFormatter.
public MoneyFormatter Build()
Returns
- MoneyFormatter
The formatter.
ElideWhenCultureMatches()
Elides the currency designator when the formatting culture's region currency matches the amount's currency.
public MoneyFormatterBuilder ElideWhenCultureMatches()
Returns
- MoneyFormatterBuilder
This builder.
WithCulture(IFormatProvider)
Sets the culture used to render the numeric component.
public MoneyFormatterBuilder WithCulture(IFormatProvider formatProvider)
Parameters
formatProviderIFormatProviderThe culture provider.
Returns
- MoneyFormatterBuilder
This builder.
WithEnglishName()
Renders the currency designator as the English-language currency name.
public MoneyFormatterBuilder WithEnglishName()
Returns
- MoneyFormatterBuilder
This builder.
WithGrouping(bool)
Sets whether digit-group separators are emitted for the numeric-only presentation.
public MoneyFormatterBuilder WithGrouping(bool includeGrouping)
Parameters
Returns
- MoneyFormatterBuilder
This builder.
WithIsoCode()
Renders the currency designator as the ISO 4217 code.
public MoneyFormatterBuilder WithIsoCode()
Returns
- MoneyFormatterBuilder
This builder.
WithMinorUnits(int)
Overrides the fractional-digit count.
public MoneyFormatterBuilder WithMinorUnits(int minorUnits)
Parameters
minorUnitsintThe explicit precision to render.
Returns
- MoneyFormatterBuilder
This builder.
WithNumericOnly()
Renders the bare numeric amount with no currency designator.
public MoneyFormatterBuilder WithNumericOnly()
Returns
- MoneyFormatterBuilder
This builder.
WithSymbol()
Renders the currency designator as the culture's native symbol.
public MoneyFormatterBuilder WithSymbol()
Returns
- MoneyFormatterBuilder
This builder.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |