Skip to content

Rupiah

Number
1500000.5
Formatted
Rp1.500.000,50
In words
satu juta lima ratus ribu rupiah lima puluh sen

Runs in your browser.

Go TypeScript Returns
rupiah.Format(a, opts) rupiah.format(n, opts?) Rp1.500.000,50
rupiah.Parse(s) rupiah.parse(s) The amount (Go: Amount in sen, TypeScript: number in rupiah)
rupiah.Valid(s) rupiah.isValid(s) Whether s parses
rupiah.Terbilang(a) rupiah.terbilang(n) satu juta lima ratus ribu rupiah lima puluh sen
  • Go uses rupiah.Amount, an int64 in sen, so arithmetic is exact: 150_000 * rupiah.Rupiah + 50 * rupiah.Sen.
  • TypeScript uses a number in rupiah. Amounts with sen are limited to below 10 trillion (MAX_SEN_AMOUNT) so they stay exact. Whole amounts go up to 999 trillion (MAX_AMOUNT).
Go Options TypeScript Effect
Decimals decimals Always print sen: Rp2.000.000,00
OmitSymbol symbol: false No Rp prefix

Without Decimals, sen is printed only when it is not zero. Negative amounts are formatted as -Rp1.000.

Parse accepts what people write in Indonesia: an optional Rp, Rp. or IDR prefix, dots as thousands separators, a comma before sen, and a trailing ,-. Rp 25.000,-, IDR 1.500.000,50 and 25000 all parse. Input is limited to 64 characters.

length, charset, format (misplaced separators, more than two sen digits), range (larger than the supported amount).

package main
import (
"fmt"
"github.com/haikalmumtaz233/nusaindex/rupiah"
)
func main() {
price := 1_500_000*rupiah.Rupiah + 50*rupiah.Sen
text, err := rupiah.Format(price, rupiah.Options{})
if err == nil {
fmt.Println(text)
}
plain, err := rupiah.Format(2_000_000*rupiah.Rupiah, rupiah.Options{Decimals: true, OmitSymbol: true})
if err == nil {
fmt.Println(plain)
}
fmt.Println(rupiah.Valid("Rp 25.000,-"))
amount, err := rupiah.Parse("Rp 25.000,-")
if err == nil {
fmt.Println(int64(amount / rupiah.Rupiah))
}
words, err := rupiah.Terbilang(price)
if err == nil {
fmt.Println(words)
}
}
Output
Rp1.500.000,50
2.000.000,00
true
25000
satu juta lima ratus ribu rupiah lima puluh sen