git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Convert a scientific notation to decimal number, and still keeping the data format as float64


On Friday, October 18, 2019 at 2:46:42 PM UTC+3, Gys wrote:
> On 10/18/19 10:35 AM, doganadres at gmail.com wrote:
> > 
> > Here is my question:
> > 
> > 
> > I am using the numpy.std formula to calculate the standart deviation. However, the result comes as a number in scientific notation.
> > Therefore I am asking, How to convert a scientific notation to decimal number, and still keep the data format as float64 ?
> > 
> > Or is there any workaround to get the initial standart deviation result as a decimal number?
> > 
> > 
> > Here is my code:
> > 
> > stdev=numpy.std(dataset)
> > print(stdev)
> >      Result: 4.999999999999449e-05
> > 
> > 
> > print(stdev.dtype)
> >      Result: float64
> > 
> > 
> > Solutions such as this:
> > 
> > stdev=format(stdev, '.10f')
> > converts the data into a string object! which I don't want.
> > 
> > 
> > Expected result: I am willing to have a result as a decimal number in a float64 format.
> > 
> > System: (Python 3.7.4 running on Win10)
> > 
> > 
> > Regards,
> > 
> 
> Hi, doganadres at gmail.com
> 
> why don't you use
> 
> print("{0:10.5f}".format(x))
> 
> The only thing you want is a specific form of the human readable 
> representation of the number. For this it is not necessary the convert 
> the  *number* itself definitely to a string. You only have to make a 
> temp copy of x for printing purposes.
> 
> Linux Mint Tara in Spyder(Python 3.6) :
> 
> x=4.999999999999449e-05
> 
> print(x)
> 4.999999999999449e-05
> 
> print("{0:8.5f}".format(x))
>   0.00005
> 
> print(x)
> 4.999999999999449e-05
> 
> hth
> Gys

Hello,

I don't only need a human readable representation of number, I need to use it further, do things such as putting it in a pandas object and saving it to an excel file.

Doing things such as 
x="{0:10.5f}".format(x)
gives a str object as a result:
<built-in method format of str object at 0x07F84A48>