goldmeltvalue

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 0 Imported by: 0

README

gold-melt-value

Go Reference

Compute precious-metal melt value from karat (purity), weight, and a live spot price. Pure, dependency-free Go math — the same engine behind the GoldGramPrice live gold gram price calculator.

Install

go get github.com/theluckystrike/gold-melt-value

Quick example

package main

import (
	"fmt"

	goldmeltvalue "github.com/theluckystrike/gold-melt-value"
)

func main() {
	spotPerOz := 3983.30 // USD per troy ounce
	grams := 10.0        // a 10 g chain
	karat := uint32(14)

	usd := goldmeltvalue.MeltValueGrams(grams, karat, spotPerOz)
	// 10 g of 14k contains ~5.83 g pure gold -> melt ~ $747.05
	fmt.Println(usd)

	fmt.Println(goldmeltvalue.Purity(karat)) // 14/24 ~= 0.5833
}

API

Function Description
Purity(karat uint32) float64 Decimal purity (karat / 24).
SpotPerGram(spotPerTroyOz float64) float64 Spot price per gram of pure metal.
MeltValueGrams(grams, karat, spotPerTroyOz) Melt value for a weight in grams.
MeltValueDwt(dwt, karat, spotPerTroyOz) Melt value for a weight in pennyweight (1 dwt = 1/20 troy oz).
MeltValueTroyOz(troyOz, karat, spotPerTroyOz) Melt value for a weight in troy ounces.

Constants: GramsPerTroyOz = 31.1034768, and karat helpers K24, K22, K18, K14, K10.

License

MIT.

Documentation

Overview

Package goldmeltvalue computes precious-metal melt value from karat (purity), weight, and a live spot price. Pure, dependency-free math — the same engine behind the GoldGramPrice live gold calculator at https://goldgramprice.com/.

Quick example:

spotPerOz := 3983.30           // USD per troy ounce
grams := 10.0                   // a 10 g chain
karat := uint32(14)
usd := goldmeltvalue.MeltValueGrams(grams, karat, spotPerOz)
// 10 g of 14k contains ~5.83 g pure gold -> melt ~ $747.05
_ = goldmeltvalue.Purity(karat) // 14/24 ~= 0.5833

Index

Constants

View Source
const (
	K24 = uint32(24)
	K22 = uint32(22)
	K18 = uint32(18)
	K14 = uint32(14)
	K10 = uint32(10)
)

Common karat purities used in jewelry (US).

View Source
const GramsPerTroyOz = 31.1034768

GramsPerTroyOz is the number of grams in one troy ounce (1 oz t = 31.1034768 g).

Variables

This section is empty.

Functions

func MeltValueDwt

func MeltValueDwt(dwt float64, karat uint32, spotPerTroyOz float64) float64

MeltValueDwt returns the melt value for a weight in pennyweight (dwt). 1 dwt = 1/20 troy oz.

func MeltValueGrams

func MeltValueGrams(grams float64, karat uint32, spotPerTroyOz float64) float64

MeltValueGrams returns the melt value (in the spot-price currency) for a given weight in grams, karat, and spotPerTroyOz.

Melt = grams * purity * (spot / 31.1034768).

func MeltValueTroyOz

func MeltValueTroyOz(troyOz float64, karat uint32, spotPerTroyOz float64) float64

MeltValueTroyOz returns the melt value for a weight in troy ounces (already in troy units).

func Purity

func Purity(karat uint32) float64

Purity returns the decimal purity for a karat value (karat / 24). Purity(24) == 1.0 (pure), Purity(18) == 0.75, Purity(14) ~= 0.5833.

func SpotPerGram

func SpotPerGram(spotPerTroyOz float64) float64

SpotPerGram returns the spot price per gram of pure metal, derived from a per-troy-ounce quote.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL