Questions tagged [leading-zero]

276 questions
610
votes
33 answers

Javascript add leading zeroes to date

I've created this script to calculate the date for 10 days in advance in the format of dd/mm/yyyy: var MyDate = new Date(); var MyDateString = new Date(); MyDate.setDate(MyDate.getDate()+10); MyDateString = MyDate.getDate() + '/' +…
Julian Coates
  • 6,129
  • 3
  • 16
  • 5
240
votes
3 answers

How to concatenate strings with padding in sqlite

I have three columns in an sqlite table: Column1 Column2 Column3 A 1 1 A 1 2 A 12 2 C 13 2 B 11 2 I need to select…
Akshara
  • 3,361
  • 9
  • 31
  • 29
173
votes
7 answers

How to remove leading and trailing zeros in a string? Python

I have several alphanumeric strings like these listOfNum = ['000231512-n','1209123100000-n00000','alphanumeric0000', '000alphanumeric'] The desired output for removing trailing zeros would be: listOfNum =…
alvas
  • 115,346
  • 109
  • 446
  • 738
118
votes
3 answers

Why does Python 3 allow "00" as a literal for 0 but not allow "01" as a literal for 1?

Why does Python 3 allow "00" as a literal for 0 but not allow "01" as a literal for 1? Is there a good reason? This inconsistency baffles me. (And we're talking about Python 3, which purposely broke backward compatibility in order to achieve goals…
walrus
  • 2,945
  • 5
  • 18
  • 19
49
votes
8 answers

Input field value - remove leading zeros

I have a textbox in Javascript. When I enter '0000.00' in the textbox, I want to know how to convert that to only having one leading zero, such as '0.00'.
raja
34
votes
4 answers

SQLite function to format numbers with leading zeroes?

I’ve got an SQLite database that will need to contain products. Those products have a fixed-format composite product number, consisting of category, group and product number (cccccc.gg.ppp). Every time a new product is inserted, the new product…
Martijn
  • 13,225
  • 3
  • 48
  • 58
24
votes
3 answers

Javascript 0 in beginning of number

I just want to understand js logic with 0-s in beginning of number. For example var x = 09.3 // here x == 9.3 // other example 09.3 == 9.3 // returns true // but check this one var x = 02.5 // Uncaught SyntaxError: Unexpected number // or this…
Gor
  • 2,808
  • 6
  • 25
  • 46
21
votes
3 answers

How to count leading zeros in a 32 bit unsigned integer

Could anyone tell me please what is an efficient algorithm to count the number of leading zeroes in a 32-bit unsigned integer in C programming?
rzmuc
  • 243
  • 1
  • 5
  • 10
17
votes
6 answers

Fast way of finding most and least significant bit set in a 64-bit integer

There are a lot of questions about this on StackOverflow. A lot. However I cannot find an answer that: Works in C# Works for 64-bit integers (as opposed to 32-bit) Faster than: private static int Obvious(ulong v) { int r = 0; while ((v >>=…
Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158
16
votes
4 answers

Get rid of leading zeros for date strings in Python?

Is there a nimble way to get rid of leading zeros for date strings in Python? In the example below I'd like to get 12/1/2009 in return instead of 12/01/2009. I guess I could use regular expressions. But to me that seems like overkill. Is there a…
c00kiemonster
  • 22,241
  • 34
  • 95
  • 133
16
votes
14 answers

Count leading zeroes in an Int32

How do I count the leading zeroes in an Int32? So what I want to do is write a function which returns 30 if my input is 2, because in binary I have 000...0000000000010.
user1310957
15
votes
4 answers

Most efficient way to remove leading zeros from Swift 3 string

I have a string such as "00123456" that I would like to have in an string "123456", with the leading zeros removed. I've found several examples for Objective-C but not sure best way to do so with Swift 3. Thanks
Jazzmine
  • 1,837
  • 8
  • 36
  • 54
15
votes
3 answers

Number to string with leading (left padded) zeros in Julialang

It seems as an easy question, but I cannot find the answer anywhere. If I have an integer variable, how can I transform it to a string with leading zeros? I want something as the code below: n = 4 string_size = 3 println(fleading(n, string_size)) #…
silgon
  • 6,890
  • 7
  • 46
  • 67
12
votes
1 answer

Convert int to string with leading zeros

I have an integer which I want to convert to a string with leading zeros. So I have 1 and want to turn it into 01. 14 should turn into 14 not 014. I tried: let str = (string 1).PadLeft(2, '0') // visual studio suggested this one let str = (string…
Snæbjørn
  • 10,322
  • 14
  • 65
  • 124
9
votes
5 answers

What directive can I give a stream to print leading zeros on a number in C++?

I know how to cause it to be in hex: unsigned char myNum = 0xA7; clog << "Output: " std::hex << int(myNum) << endl; // Gives: // Output: A7 Now I want it to always print a leading zero if myNum only requires one digit: unsigned char myNum =…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
1
2 3
18 19