StarThrower.MathUtilities 2.0.0

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

StarThrower.MathUtilities

Mathematical helper methods for common numeric operations, rounding, and numeric-string validation.

StarThrower.MathUtilities is a small collection of static helpers for numeric rounding and for checking whether a string represents a number, whole number, integer, or long — useful for validating user input before parsing.


Installation

dotnet add package StarThrower.MathUtilities

MathUtil

A static class containing all of the library's functionality.

Constants

Member Description
Degree The value of one degree in radians (Math.PI / 180.0), useful for degree↔radian conversions.

Rounding

Method Description
RoundTowardsZero(double number) Rounds toward zero — truncates the fractional part for non-negative numbers, rounds up (toward zero) for negative numbers. RoundTowardsZero(2.5) == 2, RoundTowardsZero(-2.5) == -2.
RoundTo(double value, long digits) Rounds value to digits decimal places using "round half away from zero" (Math.Floor(value * 10^digits + 0.5) / 10^digits). If digits <= 0, always rounds to the nearest whole number — it does not scale to round to the nearest power of ten for negative digits.

Numeric String Validation

These methods check whether a string can be interpreted as a particular kind of number, without throwing on invalid input:

Method Description
IsNumeric(string? test) Returns true if the string parses as a double under NumberStyles.Any (currency symbols, thousands separators, decimals, scientific notation, etc.), matching VB.NET's IsNumeric behavior. Returns false for null or empty strings.
IsWholeNumber(string? test) Returns true if the string parses as a double with no fractional component.
IsInteger(string? test) Returns true if the string parses as an int.
IsLong(string? test) Returns true if the string parses as a long.

IsWholeNumber, IsInteger, and IsLong throw ArgumentNullException if test is null; IsNumeric returns false instead.


Usage

using StarThrower.MathUtilities;

// Validate input before parsing
if (MathUtil.IsInteger(userInput))
{
    int value = int.Parse(userInput);
}

// Rounding
double rounded = MathUtil.RoundTo(3.14159, 2); // 3.14
long truncated = MathUtil.RoundTowardsZero(-7.8); // -7

// Degree/radian conversion
double radians = 45 * MathUtil.Degree;

Dependencies

None.


License

Copyright © 2026 Stephen Elmer. Licensed under the MIT License.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on StarThrower.MathUtilities:

Package Downloads
StarThrower.StringUtilities

String manipulation and analysis utilities including encoding-aware character operations with consistent cross-platform Windows-1252 behavior.

StarThrower.Gis.GeoUtilities

Geographic and coordinate system utilities including shape parsing, spatial calculations, and geometry helpers.

StarThrower.DateTimeUtilities

Date and time helper methods for common calculations, formatting, and manipulation operations.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 145 7/4/2026