### Basic Money Operations in Go Source: https://github.com/radical-app/money/blob/master/README.md Demonstrates creating money values, adding, subtracting, and checking for zero or equality using the GoLang Money library. ```go package main import ( "fmt" "github.com/radical-app/money" ) func main() { fiveEur := money.EUR(500) // see list of all currencies tenEur, err := fiveEur.Add(fiveEur) fmt.Print(err) zeroEur, err := tenEur.Subtract(tenEur) fmt.Print(err) zeroEur.IsZero() // true anotherFiveEur,err := zeroEur.Add(fiveEur) fmt.Print(err) fiveEur.IsEquals(anotherFiveEur) // true fmt.Print(fiveEur.String()) // EUR 500 for beautiful formatter see below } ``` -------------------------------- ### Creating Money from Integer Values Source: https://github.com/radical-app/money/blob/master/README.md Shows how to create money values from integer amounts using specific currency constructors or the generic Forge function. ```go usd312 := money.USD(312) usd312, err := money.Forge(312, "USD") ``` -------------------------------- ### Creating Money from Float Values Source: https://github.com/radical-app/money/blob/master/README.md Demonstrates creating money values from floating-point numbers, which should be used cautiously. ```go usd312 := money.FloatUSD(3.12) usd312, err := money.ForgeFloat(3.12, "USD") ``` -------------------------------- ### SQL Driver Support for Money Source: https://github.com/radical-app/money/blob/master/README.md Demonstrates how to insert money values into a SQL database using different formats (int64, string, float) and how the Scan operation is handled automatically. ```go _, err := db.Exec("insert into blablabla int, string, decimal (?,?,?)", money.EUR(123).Int64(), money.EUR(123).String(), money.EUR(123).Float() ) ``` ```go rows.Scan(&moneyStoredAsInt64, &moneyStoredAsString, &moneyStoredAsFloat ) ``` -------------------------------- ### Parsing Money from String Source: https://github.com/radical-app/money/blob/master/README.md Illustrates parsing money values from string representations, including handling potential errors and fallbacks. ```go usd312, err := money.Parse("USD 312") usd312.String() // "USD 312" ``` ```go eur312, err := money.ParseWithFallback("312", "EUR") // this uses EUR because the string has it eur312, err := money.ParseWithFallback("EUR 312", "JPY") // not suggested solution use ParseWithFallback if you have to deal with multiple currencies money.DefaultCurrencyCode="JPY" jpy312, err := money.Parse("312") ``` -------------------------------- ### JSON Marshaling of Money Objects Source: https://github.com/radical-app/money/blob/master/README.md Shows how to marshal a money object into a JSON format, producing a DTO with amount, currency, symbol, and cents. ```go json.Marshal(money.EUR(123)) ``` -------------------------------- ### JSON Unmarshaling into Money Objects Source: https://github.com/radical-app/money/blob/master/README.md Demonstrates unmarshaling JSON data into a money object, reconstructing the original money value. ```go m := &Money{} json.Unmarshal([]byte('{"amount":123,"currency":"EUR","symbol":"€","cents":100}'), m) ``` -------------------------------- ### Localized Money Display Source: https://github.com/radical-app/money/blob/master/README.md Uses the moneyfmt package to display money values formatted according to specific locales. ```go import "github.com/radical-app/money/moneyfmt" import "github.com/radical-app/money" moneyfmt.Display(money.EUR(123400), "ru") // € 1 234 moneyfmt.Display(money.EUR(123456), "ru") // € 1 234,56 moneyfmt.Display(money.EUR(123456), "it") // € 1.234,56 moneyfmt.Display(money.EUR(123400), "it") // € 1.234 moneyfmt.Display(money.EUR(123456), "en") // € 1,234.56 moneyfmt.Display(money.EUR(123456), "jp") // € 1,234.56 moneyfmt.Display(money.EUR(123456), "zh") // € 1,234.56 ``` -------------------------------- ### String Representation of Money Source: https://github.com/radical-app/money/blob/master/README.md Provides the basic string representation of a money value. ```go money.EUR(123).String() // "EUR 123" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.