AspDotNetCore2BinderFloatingDecimalModel 1.0.0

dotnet add package AspDotNetCore2BinderFloatingDecimalModel --version 1.0.0
                    
NuGet\Install-Package AspDotNetCore2BinderFloatingDecimalModel -Version 1.0.0
                    
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="AspDotNetCore2BinderFloatingDecimalModel" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AspDotNetCore2BinderFloatingDecimalModel" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AspDotNetCore2BinderFloatingDecimalModel" />
                    
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 AspDotNetCore2BinderFloatingDecimalModel --version 1.0.0
                    
#r "nuget: AspDotNetCore2BinderFloatingDecimalModel, 1.0.0"
                    
#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 AspDotNetCore2BinderFloatingDecimalModel@1.0.0
                    
#: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=AspDotNetCore2BinderFloatingDecimalModel&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AspDotNetCore2BinderFloatingDecimalModel&version=1.0.0
                    
Install as a Cake Tool

ASP.NET Core 3.0 BinderFloatingDecimalModel

Model Binder in ASP.NET Core 3.0 for Floating Point Numeric Values [double, float или decimal]

Use in your project:

using AspDotNetCore2BinderFloatingDecimalModel;
// ...
public class Startup
{
	// ...
	public void ConfigureServices(IServiceCollection services)
	{
		// ...
		services.AddMvc(opts =>
		{
			opts.ModelBinderProviders.Insert(0, new CustomDecimalModelBinderProvider());
		}).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
	}
}

A well-known feature of the standard model binding in ASP.NET Core 3.0 is that it is impossible to fully use floating point value types in properties. The built-in model binding tries to process all numeric values ​​as integers, even if the type of the model property is declared as a floating-point number. From here it becomes problematic to use models with properties of types [double, float or decimal] in forms.

This model binding not only fixes this problem, but also frees the user from restricting the use of a fractional separator (period or comma). This binder allows you to use any fraction separator. Any separator is forcibly replaced with a system one before conversion.

Regex FloatSeparator = new Regex(@"[.,]", RegexOptions.Compiled);
////////////////////////////////////////////////////
// replace the fractional separator with the current system
FieldValueAsNormalString = FloatSeparator.Replace(FieldValueAsNormalString, CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);

In addition, a truncated format for recording numbers is allowed. For example: 0.5 and .5 will give one result. As well as 5.0 == 5. This feature looks ambiguous and controversial ⇒ you can comment out this "value processing".

if (FloatSeparator.IsMatch(FieldValueAsString))
	FieldValueAsNormalString = "0" + FieldValueAsNormalString + "0";

Special attention is required to the regular expression pattern of the intended value. File: ** CustomFloatingModelBinder.cs **

protected readonly Regex FloatPattern = new Regex(@"^(-?)[0-9]*(?:[.,][0-9]*)?$", RegexOptions.Compiled);

Check it to meet the tasks in your context

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0 694 3/10/2020