from String
Approximates a decimal price string to a fraction.
This function uses continued fractions algorithm to approximate the decimal value to a fraction with 32-bit numerator and denominator.
Warning: This function can give unexpected results for values that cannot be represented accurately as fractions within the 32-bit integer constraints. It's safer to create Price objects directly using the constructor when you know the exact fraction.
Return
A Price object approximating the decimal value
Parameters
price
The decimal price as a string (e.g., "1.5", "0.75")
Throws
if the price string is invalid
Example
val price = Price.fromString("1.5")
println("${price.numerator}/${price.denominator}") // 3/2Content copied to clipboard