How do I go about writing a function to convert a decimal number string to a decimal and a decimal number to a string?
The valueOf method in Java can be used to convert an integer to a String. It accepts one parameter, the integer value. If the value being converted is an integer, the input value MUST be an integer!
The variable holding an integer value i.e. 10 is passed to the to_string() method which returns a corresponding string “10”. In the above example, there are three integers, num1, num2, and num3. To convert them into a string, you have passed each integer to the to_string() function and get their string representation.
There is very convenient clojure functions to convert from anything to string and from something resembling a number to BigDecimal:
user=> (bigdec "1234")
1234M
user=> (str 1234M)
"1234"
I guess this is clojure canonical way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With