Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a numeric string to number (decimal) and number to string

How do I go about writing a function to convert a decimal number string to a decimal and a decimal number to a string?

like image 616
Isuru Avatar asked May 25 '12 10:05

Isuru


People also ask

What method converts numeric values into string values?

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!

Which method is used to convert integers and decimal values to corresponding strings?

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.


1 Answers

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.

like image 141
Vladimir Matveev Avatar answered Sep 21 '22 23:09

Vladimir Matveev