In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to specify floating point digits in python. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
1. Round function
Examples are as follows:
> axiom 1.23444
Round (a, 3)
1.234
# here if you specify that the data needs to retain 3 decimal places, but the data itself has only one decimal place
# is the same as the original data
> > baked 1.2
> > round (b, 3)
1.2
# if no precision is specified, the returned result is an integer
> > round (3.5)
four
2. String formatting method
'% [width] [.resume] f'
Width specifies the width of the data, including decimals, and precision specifies precision
If the number of digits specified here is 2 digits, it will be made up even if it is not enough.
> s ='% .2f'
> > baked 1.2
> > s% b
'1.20'
The length specified here is 6 digits, which is aligned to the right by default.
> s ='% 6.2f'
> > s% b
'1.20'
If you need to change the alignment to the left, you can write it as follows
> s ='%-6.2f'
> > s% b
'1.20'
On how to specify floating-point digits in python to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.