问题标签 [leading-zero]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
1301 浏览

java - 使用 SuperCsv 写入文件,在 excel 中打开时保留前导零

我想知道是否有办法在使用 SuperCsv 时保持领先的 0。

我的问题是我有几列的数字前导为 0。我想保留 0,但 excel 不断剥离它,我还尝试在数字的开头附加一些字符,例如“=”但是没有好的结果。

Excel 显示我在数字开头添加的第一个字符,因此列值看起来像 =0222333111 ,那是因为 supercsv 可能将输出包装在引号之间。

我在 superCsv 网站上没有找到任何东西,而且我想我不是唯一一个遇到这个问题的人。我应该迁移到 Excel Java 库,还是有解决方法?

0 投票
1 回答
282 浏览

c - 计算带前导零的数字总和时C中的奇怪行为

我只是想用C写一个简约的程序来计算某个自然数的位数之和(位数之和定义如下: sumOfDigits(123) = 6, sumOfDigits(0) = 0, sumOfDigits(32013) = 9 , 等等)。

到目前为止,以下代码片段一切正常。例如,对于 5100,它正确地提供了 6 个。但是,为什么 05100 交付了 14(还记得前面的 0)吗?

这里发生了什么?

我查看了数字的二进制表示,但这并没有给我任何信息。(顺便说一句:我猜下面的代码应该可以在任何地方运行。)

编辑:正如 Zaibis 所说....前导 0 表示八进制表示法。:-) 等等:5100_8 == 2624_10

0 投票
1 回答
839 浏览

mysql - 如何通过ods从phpmyadmin导入mysql db中的前导零

我有带前导零的 .ods ID 列:01344、01345、01222...
我将该列格式化为类别>文本。

Ods 文件是通过 phpMyAdmin > import > from ods... 导入的

在表 ID 列中设置如下: char(13) MIME: Text/Plain utf8_general_ci

问题是前导零总是丢失。这不好。

我尝试将 ID 值包含在“01344”和“01344”中。导入带引号的值:(

任何想法如何在 mysql 表中导入前导零?

0 投票
2 回答
31 浏览

sql - 创建 1000 个带前导 0 的函数

早上好 DBA,我需要一个函数来提取一个 int DocumentID 列并返回最低的千位 int。限制是我们的结果必须有 8 个字符,并且前导字符必须是 0。

  • 示例 1:1234(包含在 DocumentID 列中的 int)结果:00001000(由结果集中的函数生成)

  • 示例 2:1152534 结果:01152000

结果集...

0 投票
0 回答
94 浏览

add - 为一个表中的所有记录添加前导 0

我的数据库中有近 17,000 个书名。ISBN 字段丢失了前导 0。有没有简单的方法可以一次将此数字添加到所有条目中?ISBN 应该是 10 位长,但所有都只显示最后 9 位。

0 投票
3 回答
15035 浏览

php - PHP从数字中去除前导零0

我发布这个是因为这不是大多数新手可能熟悉的东西。

问题

我们有一个使用数字 ID 的票务系统。现在公司中的一些人喜欢在票号前面加上零,有些人会在没有前导零的情况下引用它,这是正确的方法。因此,为了标准化输出,我们必须删除前导零。

这听起来很简单,但我们不能只在它上面运行 str_replace,因为这可能会删除数字中间的有效 0。

现在你可以预匹配并做各种时髦的事情来找到答案,但最简单的是将数字字符串转换为 int。

让我们以以下用户为例:

您应该打印出以下内容:

45678

0045678

现在基本上这些对于应用程序是相同的,但我希望能够满足人们以不正确的格式输入信息。

0 投票
4 回答
4359 浏览

r - 添加条件前导零或尾随零

我需要有条件地添加前导零或尾随零的帮助。

我有一个数据框,其中一列包含 icd9 诊断。作为向量,该列看起来像:

我需要所有值的长度为 5,包括中间的句点(不包括“”)。如果值在句点之前有一位,则需要有一个前导零。如果值在句点后有一位,则末尾需要为零。所以结果应该是这样的:

这是 R 的向量:

0 投票
1 回答
76 浏览

html - 添加leadingzero 做我的倒计时 JavaScript

有人可以帮我添加一个前导零做我的倒计时 JavaScript。尝试了 3 个小时,现在我快疯了……这是干净的倒计时,没有我做过的任何奇怪的编码:

0 投票
1 回答
1712 浏览

r - Adding leading zeroes to dataframe column using sprintf in R

I have a dataframe and want the number variable to be four digits long, in order to do this I need to add between 1-3 leading zeroes, the method I chose to do this is the sprintf function, as it is immaterial that the number is converted to character class. Unfortunately the results are not coming out in the order I want

The test data frame is made as follows and the leading 0 column added on as a third column to allow easy comparison. As can be seen by running the code the order that the leading zero numbers are pasted in does not correspond to the original number order

by rearranging the data frame order alphabetically by classing the original number column as characters, the sprintf number are now in ascending order although the number series is not.

I can create the desired data set by Frankensteining it togther.

However I would like to know what I am doing wrong and what method would give me the result I expected to get from what I thought was a simple operation!

0 投票
1 回答
20260 浏览

cobol - 抑制 COBOL 中的前导零

我曾尝试在网上查找此内容,但找不到与我的情况相符的任何内容。我需要抑制输出中的前导零,但我无法让它正常工作。我需要抑制的数字是 PR-PAY-RATE。