
Arbitrary-precision decimal arithmetic with operator-overloaded, type-safe numbers; easy construction, conversions, comparisons, collection extensions, constants, accurate financial operations, and sample app demonstrating usage.
A Kotlin Multiplatform library providing arbitrary-precision decimal arithmetic across Android, iOS, and JVM platforms.
java.math.BigDecimal)java.math.BigDecimal)NSDecimalNumber)Add the dependency to your commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("jp.co.tanocee:bikdecimal:1.0.0")
}
}
}import jp.co.tanocee.bikdecimal.BikDecimal
val a = BikDecimal("123.45")
val b = BikDecimal("67.89")
val sum = a + b // 191.34
val difference = a - b // 55.56
val product = a * b // 8382.2205
val quotient = a / b // 1.818...// From String
val fromString = BikDecimal("999.99")
// From Double
val fromDouble = BikDecimal(3.14159)
// From Long
val fromLong = BikDecimal(42L)val zero = BikDecimal.ZERO // 0
val one = BikDecimal.ONE // 1val x = BikDecimal("100")
val y = BikDecimal("200")
when {
x < y -> println("x is less than y")
x > y -> println("x is greater than y")
x == y -> println("x equals y")
}
// Or use compareTo directly
x.compareTo(y) // Returns negative, zero, or positiveval value = BikDecimal("123.456")
val asString = value.toPlainString() // "123.456"
val asDouble = value.toDouble() // 123.456
val asLong = value.toLong() // 123// String to BikDecimal with default value
val valid = "100.5".toBikDecimal() // BikDecimal("100.5")
val invalid = "invalid".toBikDecimal() // BikDecimal.ZERO (default)
val custom = "invalid".toBikDecimal(BikDecimal.ONE) // BikDecimal.ONE
// Sum of collection
data class Product(val name: String, val price: String)
val products = listOf(
Product("Apple", "1.20"),
Product("Banana", "0.80"),
Product("Orange", "1.50")
)
val total = products.sumOf { it.price.toBikDecimal() } // 3.50val value = BikDecimal("42.5")
val negated = value.negative() // -42.5The sample module contains a Compose Multiplatform application demonstrating all features of BikDecimal. You can run it to see interactive examples of:
sumOf
Android:
./gradlew :sample:assembleDebugiOS:
Open the project in Xcode and run the sample target.
commonMain - Common API and extension functionsandroidMain - Android implementation using java.math.BigDecimal
jvmMain - JVM implementation using java.math.BigDecimal
iosMain - iOS implementation using NSDecimalNumber
To build the library:
./gradlew :bikdecimal-core:buildTo build the entire project including the sample app:
./gradlew buildA Kotlin Multiplatform library providing arbitrary-precision decimal arithmetic across Android, iOS, and JVM platforms.
java.math.BigDecimal)java.math.BigDecimal)NSDecimalNumber)Add the dependency to your commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("jp.co.tanocee:bikdecimal:1.0.0")
}
}
}import jp.co.tanocee.bikdecimal.BikDecimal
val a = BikDecimal("123.45")
val b = BikDecimal("67.89")
val sum = a + b // 191.34
val difference = a - b // 55.56
val product = a * b // 8382.2205
val quotient = a / b // 1.818...// From String
val fromString = BikDecimal("999.99")
// From Double
val fromDouble = BikDecimal(3.14159)
// From Long
val fromLong = BikDecimal(42L)val zero = BikDecimal.ZERO // 0
val one = BikDecimal.ONE // 1val x = BikDecimal("100")
val y = BikDecimal("200")
when {
x < y -> println("x is less than y")
x > y -> println("x is greater than y")
x == y -> println("x equals y")
}
// Or use compareTo directly
x.compareTo(y) // Returns negative, zero, or positiveval value = BikDecimal("123.456")
val asString = value.toPlainString() // "123.456"
val asDouble = value.toDouble() // 123.456
val asLong = value.toLong() // 123// String to BikDecimal with default value
val valid = "100.5".toBikDecimal() // BikDecimal("100.5")
val invalid = "invalid".toBikDecimal() // BikDecimal.ZERO (default)
val custom = "invalid".toBikDecimal(BikDecimal.ONE) // BikDecimal.ONE
// Sum of collection
data class Product(val name: String, val price: String)
val products = listOf(
Product("Apple", "1.20"),
Product("Banana", "0.80"),
Product("Orange", "1.50")
)
val total = products.sumOf { it.price.toBikDecimal() } // 3.50val value = BikDecimal("42.5")
val negated = value.negative() // -42.5The sample module contains a Compose Multiplatform application demonstrating all features of BikDecimal. You can run it to see interactive examples of:
sumOf
Android:
./gradlew :sample:assembleDebugiOS:
Open the project in Xcode and run the sample target.
commonMain - Common API and extension functionsandroidMain - Android implementation using java.math.BigDecimal
jvmMain - JVM implementation using java.math.BigDecimal
iosMain - iOS implementation using NSDecimalNumber
To build the library:
./gradlew :bikdecimal-core:buildTo build the entire project including the sample app:
./gradlew build