Mailing List Archive


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

Re: [tlug] big number calculation to small number using Python



On Mon, 22 Mar 2021 23:54:32 +0000, James Tobin <jamesbtobin@example.com> wrote:

> rather than showing the true number i want to display to the user (on
> the screen) the smaller (scientific notation) number, i.e. if the
> input is 2222222222222222222222 display as xxxxe+

> the user is not constrained by how many digits they can key in which
> is why i want to display the calculations (based on their input) using
> smaller number equivalents

j@j:~/jupyter$ echo 2222222222222222222222 | python3 -c 'x=float(input()); n_digits=3; print(f"{x:.{n_digits}g}")'
2.22e+21
j@j:~/jupyter$ 

Fuss with using e, f, or g conversion code.


Home | Main Index | Thread Index