Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing scientific notation from float

Tags:

ruby

I'm currently multiplying two floats like so: 0.0004 * 0.0000000000012 = 4.8e-16

How do I get the result in a normal format, i.e. without the scientific notation, something like 0.0000000000324 and then round it up to say 5 numbers.

like image 735
bytebiscuit Avatar asked Apr 21 '12 17:04

bytebiscuit


People also ask

How do you stop scientific notation when printing float values?

Summary: Use the string literal syntax f"{number:. nf}" to suppress the scientific notation of a number to its floating-point representation.

How do I get rid of E+ in Python?

How do you stop e+ in Python? Use a string literal to suppress scientific notation Use the string literal syntax f"{num:. nf}" to represent num in decimal format with n places following the decimal point.

How do I get rid of scientific notation in Python?

In the Format Cells window, (1) select the Number category, (2) set the number of decimal places to 0, and (3) click OK. Now the scientific notation is removed.


1 Answers

You can use string formatting.

a =  0.0004 * 0.0000000000012 # => 4.8e-16
'%.5f' % a # => "0.00000"

pi = Math::PI # => 3.141592653589793
'%.5f' % pi # => "3.14159"
like image 171
Sergio Tulentsev Avatar answered Sep 20 '22 11:09

Sergio Tulentsev