当前位置:网站首页>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
边栏推荐
- 实现领域驱动设计 - 使用ABP框架 - 创建实体
- [one picture series] one picture to understand Tencent Qianfan apaas
- Optimization of MP4 file missing seconds caused by TS files when downloading videos from easydss video platform
- The second phase of freshman engineering education seminar is to enroll in the China 100 school peer program
- 16 safety suggestions from metamask project to solid programmers
- openGauss内核:简单查询的执行
- 如何化解35岁危机?华为云数据库首席架构师20年技术经验分享
- Are you still working hard to select *? Then put away these skills
- Redis' contribution in the field of microservices
- Teach you how to use airtestide to connect your mobile phone wirelessly!
猜你喜欢
华为AppLinking中统一链接的创建和使用
Understanding openstack network
Who is the fish and who is the bait? Summary of honeypot recognition methods from the perspective of red team
Preparation and operation & Maintenance Guide for 'high concurrency & high performance & high availability service program'
Nifi from introduction to practice (nanny level tutorial) - environment
黄金年代入场券之《Web3.0安全手册》
Parti,谷歌的自回归文生图模型
Use abp Zero builds a third-party login module (I): Principles
The agile way? Is agile development really out of date?
I have fundamentally solved the problem of wechat occupying mobile memory
随机推荐
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
用一个软件纪念自己故去的母亲,这或许才是程序员最大的浪漫吧
Use abp Zero builds a third-party login module (I): Principles
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
How can junior middle school developers effectively reduce their own workload?
How can ffmpeg streaming to the server save video as a file through easydss video platform?
谁是鱼谁是饵?红队视角下蜜罐识别方式汇总
Implement Domain Driven Design - use ABP framework - create entities
Kubernetes集群部署
One hour is worth seven days! Ingenuity in the work of programmers
[day ui] affix component learning
我从根上解决了微信占用手机内存问题
nifi从入门到实战(保姆级教程)——环境篇
关于被黑数据库那些事
Detailed explanation of abstractqueuedsynchronizer, the cornerstone of thread synchronization
Baidu simian: talk about persistence mechanism and rdb/aof application scenario analysis!
Boss direct employment IPO: both the end and the beginning
“有趣” 是新时代的竞争力
How can the new webmaster avoid the ups and downs caused by SEO optimization?
On the difference between process and thread