我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

保持数字相同的长度

I'm completing an example involving a clock, so I'm working with integers between 0 and 60 in some cases, and 0 and 12 in others. I need the length of each number to be two digits long, even when the value is less than 10.

For example

0  => 00
2  => 02
10 => 10
etc

I want to have them formatted, but not necessarily to print them out. What's the easiest way to achieve this?

This is probably what you want:

fmt.Printf("%02d", number)

Have a look at fmt's documentation to understand how it works.

近期文章

  • 在同一行上打印多行字符串
  • 从Golang中的嵌套动态键json获取数据
  • 如何修复不带标题的zlib文件?
  • 从Go中的数组返回指针数组
  • Golang:如何创建未知(动态)贴图长度
  • 如何使用适用于Go的AWS开发工具包创建EMR集群
  • 选择完成后,此FOR循环中断如何进行
  • 这些功能在golang中有什么区别?
  • 如何从Handler类型获取响应头?
  • Firebase自定义身份验证传递令牌
  • 大猩猩jsonrpc得到空响应
  • 如何填充嵌套的golang结构,其中包含结构数组
  • 在这种情况下[nil]到底在做什么(nil)
  • 如何在Go模板中更新字段值
  • 可变浮点精度格式字符串
  • 使用Go从Gmail API解码邮件正文
  • Golang索引模板,包括
  • GO中运行时来自该类型的struct的新实例
  • 正常关闭负面的WaitGroup
  • Go worker应用未在Cloud Foundry中启动

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华