RoundDecimal.Fody 1.0.5

dotnet add package RoundDecimal.Fody --version 1.0.5
                    
NuGet\Install-Package RoundDecimal.Fody -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RoundDecimal.Fody" Version="1.0.5">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RoundDecimal.Fody" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="RoundDecimal.Fody">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RoundDecimal.Fody --version 1.0.5
                    
#r "nuget: RoundDecimal.Fody, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RoundDecimal.Fody@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RoundDecimal.Fody&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=RoundDecimal.Fody&version=1.0.5
                    
Install as a Cake Tool

RoundDecimal.Fody

NuGet version

A Fody add-in that automatically rounds decimal properties to a specified precision. This allows you to enforce rounding rules directly on your model properties.

How To Use

1. Install the NuGet Package

Install the RoundDecimal.Fody package into your project from NuGet.

This will add the package and automatically create a FodyWeavers.xml file in your project root.

2. Add the [RoundDecimal] Attribute

Decorate any decimal or decimal? property with the [RoundDecimal] attribute. The attribute takes a single integer argument, which is the number of decimal places to round to.

## RoundDecimal.Fody

[![NuGet version](https://badge.fury.io/nu/RoundDecimal.Fody.svg)](https://badge.fury.io/nu/RoundDecimal.Fody)

RoundDecimal.Fody is a Fody weaver that automatically rounds assigned values for `decimal` and `decimal?` properties to a configured precision at compile time. Use it to enforce consistent rounding rules in your domain models without manual rounding logic.

## Quick start

1. Add the NuGet package to your project (PackageReference):

```xml
<PackageReference Include="RoundDecimal.Fody" Version="1.0.0" />
<PackageReference Include="Fody" Version="6.*" PrivateAssets="all" />
  1. Ensure a FodyWeavers.xml file exists in your project root and contains RoundDecimal.Fody:
<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
    <RoundDecimal.Fody />
</Weavers>
  1. Add the attribute to your properties:
using RoundDecimal.Fody;

public class Invoice
{
        // Rounded to 2 decimal places
        [RoundDecimal(2)]
        public decimal? Total { get; set; }

        // Rounded to 3 decimal places
        [RoundDecimal(3)]
        public decimal Fee { get; set; }
}

The weaver injects rounding logic into the property setter so the value stored in the backing field is the rounded result. Nullable properties (decimal?) are left null when null is assigned; non-null values are rounded.

Behavior example

Before weaving (your source):

var invoice = new Invoice();
invoice.Total = 123.4567m; // source assignment

After weaving (what runs at runtime):

// the value stored in the backing field will be rounded to the configured precision
invoice.Total == 123.46m; // if precision = 2

Compatibility

  • Targets typical .NET SDK projects (netstandard / net5+/net6+/net7+/net8+/net9+ as supported by Fody and your environment). Test against the target framework you use.

Publishing (for maintainers)

  • Build and pack the weaver project (it is distributed as a NuGet package with a weaver/ assembly):
dotnet build
dotnet pack -c Release
  • Push to NuGet.org (use your API key and the correct package path):
dotnet nuget push "nupkgs/RoundDecimal.Fody.*.nupkg" --api-key <API_KEY> --source https://api.nuget.org/v3/index.json

Note: Fody weavers expect the weaver assembly to be placed in the package weaver/ folder so Fody can find and run it during build. See the Fody docs for packaging guidelines.

Troubleshooting

  • TypeLoadException related to System.Nullable\1` often indicates the weaver injected references that don't match the target assembly scope. The weaver attempts to import references using the target module; if you see errors, please open an issue with a small repro (target framework and a minimal class with the attribute).
  • If the weaver does not run, ensure Fody is installed and FodyWeavers.xml contains the weaver entry.

Contributing

Contributions are welcome. Please open issues or pull requests with clear repros and tests.

License

Specify your license here (e.g., MIT). If you have a LICENSE file, reference it.


If you'd like, I can also add a short example project showing the before/after or add automated tests that validate rounding behavior during build.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 220 10/29/2025
1.0.4 208 10/29/2025
1.0.3 207 10/29/2025
1.0.2 201 10/28/2025
1.0.1 201 10/28/2025
1.0.0 203 10/28/2025