CannabisMath.Core 0.1.0

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

CannabisMath

.NET Tests License

CannabisMath is a C# cannabis calculation library for potency, dosing, weight conversions, pricing, packaging, taxes, rounding, and retail value calculations.

Built for cannabis apps, dashboards, dispensary tooling, POS workflows, inventory systems, calculators, and data projects.

Reliable weed math. Tested, reusable, and ready to port.


Status

Current version: v0.1.0

CannabisMath is an early-stage library with a stable core calculation engine.


Quick Start

using CannabisMath.Core.Composites;

var pricePerMg = CannabisValueCalculator.PricePerMgFromWeightAndPotency(
    price: 35m,
    weightGrams: 3.5m,
    potencyPercent: 20m
);
// 0.05

Why CannabisMath?

Cannabis calculations are often inconsistent across apps, dashboards, and POS systems. Differences in rounding, weight assumptions, potency formulas, and tax handling can lead to mismatched results and operational issues.

CannabisMath provides a single, deterministic calculation layer to ensure consistent results across systems.


Features

  • Potency calculations

    • Total THC from THC + THCA
    • Total CBD from CBD + CBDA
  • Weight conversions

    • Grams to retail eighths
    • Retail eighths to grams
    • Retail ounces to grams
    • Exact ounces and pounds
  • Dosing calculations

    • Milligrams per serving
    • Total mg from weight and potency
    • Mg per gram
    • Dab mg estimates
  • Pricing calculations

    • Price per gram
    • Price per mg
    • Discounted price
    • Savings amount
  • Packaging calculations

    • Full sellable units from bulk weight
    • Remaining grams
    • Bulk-to-retail breakdowns
  • Composite value calculations

    • Price per mg from weight and potency
    • Price per gram after discount
    • Price per mg after discount
  • Tax calculations

    • Tax amount
    • Total with tax
    • Combined tax rates
    • Decimal rate support
  • Rounding utilities

    • Currency rounding
    • Weight rounding
    • Milligram rounding
    • Percent rounding
    • Cash rounding to nearest nickel
    • Round up/down to nickel
    • Custom increment rounding
    • Rounding difference tracking

Project Structure

CannabisMath/
  src/
    CannabisMath.Core/
      Composites/
      Dosing/
      Packaging/
      Potency/
      Pricing/
      Rounding/
      Taxes/
      Weights/

  tests/
    CannabisMath.Core.Tests/
      Composites/
      Dosing/
      Packaging/
      Potency/
      Pricing/
      Rounding/
      Taxes/
      Weights/

Installation

This project is not published to NuGet yet.

For now, clone the repo and reference the project locally:

git clone https://github.com/LJrobinson/CannabisMath.git

Then add a project reference from another C# project:

dotnet add reference path/to/CannabisMath/src/CannabisMath.Core/CannabisMath.Core.csproj

Examples

Potency

using CannabisMath.Core.Potency;

var totalThc = PotencyCalculator.CalculateTotalThc(
    thcPercent: 1.2m,
    thcaPercent: 24.8m
);

Weight Conversions

using CannabisMath.Core.Weights;

var eighths = WeightConverter.GramsToRetailEighths(28m);

Dosing

using CannabisMath.Core.Dosing;

var totalMg = DoseCalculator.TotalMgFromPercent(3.5m, 20m);

Pricing

using CannabisMath.Core.Pricing;

var pricePerGram = PriceCalculator.PricePerGram(35m, 3.5m);

Packaging

using CannabisMath.Core.Packaging;

var breakdown = PackageCalculator.Breakdown(453.59237m, 3.5m);

Rounding

using CannabisMath.Core.Rounding;

var cashTotal = RoundingCalculator.RoundCashToNearestNickel(10.03m);

Test Coverage

Run all tests:

dotnet test

Current test count:

68 passing tests


Design Goals

  • Simple to use
  • Deterministic
  • Well-tested
  • Decimal-based for financial and retail calculations
  • Easy to port to JavaScript and Python
  • Useful for real cannabis retail workflows

Roadmap

  • NuGet package publishing
  • JavaScript / TypeScript port
  • Python port
  • Shared cross-language test fixtures
  • Result models / DTOs
  • Jurisdiction-aware tax configs
  • Margin and promo math

Disclaimer

CannabisMath is a calculation library, not legal or tax advice.


License

MIT

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

    • No dependencies.

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
0.1.0 150 4/25/2026