Soenneker.Extensions.Decimal
4.0.628
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Extensions.Decimal --version 4.0.628
NuGet\Install-Package Soenneker.Extensions.Decimal -Version 4.0.628
<PackageReference Include="Soenneker.Extensions.Decimal" Version="4.0.628" />
<PackageVersion Include="Soenneker.Extensions.Decimal" Version="4.0.628" />
<PackageReference Include="Soenneker.Extensions.Decimal" />
paket add Soenneker.Extensions.Decimal --version 4.0.628
#r "nuget: Soenneker.Extensions.Decimal, 4.0.628"
#:package Soenneker.Extensions.Decimal@4.0.628
#addin nuget:?package=Soenneker.Extensions.Decimal&version=4.0.628
#tool nuget:?package=Soenneker.Extensions.Decimal&version=4.0.628
Soenneker.Extensions.Decimal
Formatting, rounding, conversion, and zero-safe division extensions for decimal.
Installation
dotnet add package Soenneker.Extensions.Decimal
Currency
using Soenneker.Extensions.Decimal;
string display = 1234.567m.ToCurrencyDisplay(); // "$1,234.57"
string whole = 1234.5m.ToCurrencyDisplay(true); // "$1,234"
decimal amount = 12.345m.ToCurrency(); // 12.34m
decimal wholeAmount = 12.5m.ToCurrency(false); // 12m
decimal? missing = null;
string? missingDisplay = missing.ToCurrencyDisplay(); // null
ToCurrencyDisplay() deliberately produces US-style display text: $, comma grouping, a dot decimal separator, and a leading minus sign for negative values. It does not use the current culture. Both currency methods use MidpointRounding.ToEven; the Boolean parameters differ: excludePlaces controls display, while includePlaces controls the decimal result.
Percent display
ToPercentDisplay() treats the input as a fraction, multiplies it by 100, keeps up to two decimal places, and appends %.
0.25m.ToPercentDisplay(); // "25%"
0.3333m.ToPercentDisplay(); // "33.33%"
The numeric portion uses the current culture's decimal separator. Very large values can overflow when scaled by 100.
Rounding and conversion
decimal rounded = 2.345m.ToRounded(2); // 2.34m; midpoint-to-even
decimal? optional = ((decimal?)null).ToRounded(2); // null
int integer = 2.5m.ToInt(); // 2; midpoint-to-even
double approximate = 1.1m.ToDouble();
ToRounded() accepts 0 through 28 fractional digits. ToInt() throws when the rounded value is outside the Int32 range. Decimal-to-double conversion can lose precision.
Zero-safe division
decimal ratio = 10m.SafeDivision(4m); // 2.5m
decimal zero = 10m.SafeDivision(0m); // 0m
Use SafeDivision() only when a zero denominator should intentionally produce zero; it can otherwise hide invalid input.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Soenneker.Extensions.Decimal:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.Float
A collection of useful floating point extension methods |
|
|
Soenneker.Utils.Math
Some useful math related utility methods |
|
|
Soenneker.Stripe.Extensions.Decimals
Estimates card and ACH fees, net proceeds, gross-up amounts, and fee breakdowns using configurable package assumptions. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.640 | 309 | 11/18/2026 |
| 11.0.639 | 340 | 11/11/2026 |
| 11.0.638 | 167 | 11/10/2026 |
| 11.0.637 | 598 | 10/26/2026 |
| 4.0.636 | 871 | 10/14/2026 |
| 4.0.635 | 175 | 10/14/2026 |
| 4.0.630 | 200 | 10/12/2026 |
| 4.0.629 | 153 | 10/12/2026 |
| 4.0.628 | 207 | 10/11/2026 |
| 4.0.627 | 616 | 9/24/2026 |
| 4.0.626 | 477 | 9/15/2026 |
| 4.0.625 | 272 | 9/12/2026 |
| 4.0.624 | 420 | 8/30/2026 |
| 4.0.623 | 208 | 8/29/2026 |
| 4.0.622 | 966 | 7/27/2026 |
| 4.0.621 | 498 | 7/16/2026 |
| 4.0.620 | 1,146 | 6/18/2026 |
| 4.0.619 | 696 | 6/5/2026 |
| 4.0.617 | 1,351 | 3/12/2026 |
| 4.0.616 | 192 | 3/12/2026 |
Fix release metadata shell injection