PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 7, 2022

[FIXED] How can I keep the trailing zereos with .3g?

 August 07, 2022     decimal, numbers, python, significant-digits     No comments   

Issue

I have the following value: 6.095651174e-09 and I am printing it like this:

print(f' the result is: {forces[index]: .3g} N') 

Here the output is 6.1e-09 but I want to keep the zero after it was rounded from 6.09 to 6.1. My desired output would be: 6.10

A normal float works with this. But with g it does not work anymore. I want to keep the E at the end and therefore I want to stay with g (and not f).

Is it possible to have 6.10e-09 printed out here? I only found things for float and those solutions did not work with my case.

Thanks for every help!


Solution

I don't have the issue with the e type:

i = 6.0956e-9
print(f'result: {i: .2e} N')

Output:

result:  6.10e-09 N


Answered By - mozway
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing