当前位置:网站首页>8 - Format integers and floating point numbers
8 - Format integers and floating point numbers
2022-06-24 13:24:00 【ruochen】
Integer formatting
- Please format an integer , Press 10 An output , Insufficient 10 Fill in the front 0
n = 1234 print(format(n, '10d')) # Zero filling on the left side print(format(n, '0>10d')) # Right zero padding print(format(n, '0<10d'))
1234
0000001234
1234000000
Floating point format
- Format a floating point number , Keep two decimal places
x1 = 1234.5678 x2 = 58.1 # Keep two decimal places print(format(x1, '0.2f')) print(format(x2, '0.2f'))
1234.57
58.10
3. Please describe format The main usage of function
# format The function is used to format a numeric value , Specify the formatting rule through the second parameter # Right alignment print(format(x2, '*>12.2f')) # Align left print(format(x2, '*<12.2f')) # Center alignment print(format(x2, '*^12.2f')) # Divide... With thousands print(format(123455678, ',')) # Use... For integers ',' Division , And keep two decimal places print(format(123456.12321, ',.2f')) # Output according to scientific counting method print(format(x1, 'e')) # Keep two decimal places , Scientific counting outputs print(format(x1, '0.2E'))
*******58.10
58.10*******
***58.10****
123,455,678
123,456.12
1.234568e+03
1.23E+03
边栏推荐
- How can ffmpeg streaming to the server save video as a file through easydss video platform?
- 谁是鱼谁是饵?红队视角下蜜罐识别方式汇总
- Without home assistant, zhiting can also open source access homekit and green rice devices?
- CPU status information us, sy and other meanings
- Opengauss kernel: simple query execution
- Gateway processing flow of zuul source code analysis
- 初中级开发如何有效减少自身的工作量?
- what the fuck! I'm flattered. He actually wrote down the answers to the redis interview questions that big companies often ask!
- How can junior middle school developers effectively reduce their own workload?
- Resolve symbol conflicts for dynamic libraries
猜你喜欢

Main steps of system test

go Cobra命令行工具入门

go Cobra命令行工具入门

The agile way? Is agile development really out of date?

Concept + formula (excluding parameter estimation)

Detailed explanation of abstractqueuedsynchronizer, the cornerstone of thread synchronization

手把手教你用AirtestIDE无线连接手机!

Brief introduction to cluster analysis

不用Home Assistant,智汀也开源接入HomeKit、绿米设备?

#云原生征文#Ingress案例实战
随机推荐
MySQL master-slave replication
Explain the difference between iaas/paas/saas by cooking rice
About the hacked database
CVPR 2022 | 美團技術團隊精選論文解讀
Configure Yum proxy
华为AppLinking中统一链接的创建和使用
Appium installation
一文讲透研发效能!您关心的问题都在
openGauss内核:简单查询的执行
不用Home Assistant,智汀也开源接入HomeKit、绿米设备?
黄金年代入场券之《Web3.0安全手册》
Why is open source technology so popular in the development of audio and video streaming media platform?
Understanding openstack network
How does webrtc obtain video stream data on the C ++ side?
Beauty of script │ VBS introduction interactive practice
Brief introduction to cluster analysis
Getting started with the lvgl Library - colors and images
I enlighten a friend and my personal understanding of the six patriarchs' Tan Jing
One hour is worth seven days! Ingenuity in the work of programmers
Creation and use of unified links in Huawei applinking