Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to toggle scientific notation in Clojure?

I am trying to solving pythonchallenge problem using Clojure:

(java.lang.Math/pow 2 38)

I got

2.74877906944E11

However, I need to turn off this scientific notation. I searched clojure docs, still don't know what to do. Is there a general way to toggle on/off scientific notation in Clojure?

Thanks.

like image 358
Nick Avatar asked Sep 15 '25 14:09

Nick


1 Answers

You can use format to control how results are printed.

user> (format "%.0f" (Math/pow 2 38))
"274877906944"

Also, if there is no danger of losing wanted data, you can cast to an exact type:

user> 274877906944.0
2.74877906944E11
user> (long 274877906944.0)
274877906944

There are BigInts for larger inputs

user> (bigint 27487790694400000000.0)
27487790694400000000N
like image 190
noisesmith Avatar answered Sep 18 '25 10:09

noisesmith