当前位置:网站首页>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
边栏推荐
猜你喜欢

Kubernetes集群部署

Brief introduction to cluster analysis

一文讲透研发效能!您关心的问题都在

How stupid of me to hire a bunch of programmers who can only "Google"!

Use abp Zero builds a third-party login module (I): Principles

Yolov6: the fast and accurate target detection framework is open source

Getting started with the lvgl Library - colors and images
![[database] final review (planning Edition)](/img/94/cd2df3a011c4e466df5aaa0f3bd0f2.png)
[database] final review (planning Edition)

Internet of things? Come and see Arduino on the cloud

openGauss内核:简单查询的执行
随机推荐
The difference between apt and apt get
Definition and use of constants in C language
实现领域驱动设计 - 使用ABP框架 - 创建实体
go Cobra命令行工具入门
华为AppLinking中统一链接的创建和使用
Richard Sutton, the father of reinforcement learning, paper: pursuing a general model for intelligent decision makers
I have fundamentally solved the problem of wechat occupying mobile memory
Implement Domain Driven Design - use ABP framework - create entities
MySQL master-slave replication
39 - read XML node and attribute values
Beauty of script │ VBS introduction interactive practice
CVPR 2022 | 美团技术团队精选论文解读
CVPR 2022 | 美團技術團隊精選論文解讀
Yolov6: the fast and accurate target detection framework is open source
[day ui] affix component learning
How does webrtc obtain video stream data on the C ++ side?
爱可可AI前沿推介(6.24)
Leetcode 1218. Longest definite difference subsequence
黄金年代入场券之《Web3.0安全手册》
Pycharm中使用Terminal激活conda服务(终极方法,铁定可以)