Notepad++ find and replace number, digit format - numbers

I have single and two digit number, and I want to make it 4 digits.
So "1" become "0001", "22" become "0022"
How do I do that?

You have to do two replacements:
search: \b(\d\d)\b
replace: 00$1
and:
search: \b(\d)\b
replace: 000$1

Generalising the question. Suppose we want to convert a collection of numbers so that all have, say, 7 digits by adding leading zeroes as necessary. This can be done in two steps.
Add 7 leading zeroes to each number, so eg 2 33 456 789012 becomes 00000002 000000033 0000000456 0000000789012.
Convert each number to have the required number of digits by removing some leading zeroes to leave the wanted 7 digits.
In more detail.
Search for \b(\d{1,6})\b which finds numbers with between 1 and 6 digits inclusive. Replace them with 0000000\1. There is no need to search for 7-digit numbers as they are already the correct length.
Search for \b0+(\d{7})\b and replace with \1.
Notes
Input numbers that have more than 7 digits will not be found by step 1.
Input numbers that have leading zeros with less than 7 significant digits, e.g. 001234 will have the 7 zeroes added by step 1 whereas 00000000000001234 is longer than 7 digits and so will not be changed by step 1.
Input numbers with leading zeroes and more than 7 significant digits will not be changed.

I used \1 instead of $1
First Replacement:
search: (\d\d)
replace: 00\1
Second Replacement:
search: (\d)
replace: 000\1

Related

How can I check if number is out specified hexa range?

How can I write regular expression that recognize any expression from this form: "\xdd" while dd represents hexadecimal number out of the range 00-7F ?
Regular expressions do not express numerical ranges, but sequences of characters in a character set. You have to express those ranges one character at a time.
So the hex digits are [0-9A-F] which describes the set of characters for one digit using the two ranges [0-9] and [A-F] (you'd also have to decide if lower case letters are permitted). For two digits you'd have to notice that the first digit is of a shorter range using only [0-7]. The combined result would be:
[0-7][0-9A-Fa-f]
Putting the other symbols in place we could get:
\\x[0-7][0-9A-Fa-f]
(Assuming \ is a meta-character that needs escaping).

length and precision issue in Postgres

I'm using postgres sql I need 12 digits and after decimal I need only 6 digits what length & Precision should I give in columns.what datatype shold I give to cloumn.
I tried numeric as a datatype and length I give to column is 12 and precision is 6.
If you need 12 digits before the decimal and 6 digits after, you need numeric(18,6)
Quote from the manual
The scale of a numeric is the count of decimal digits in the fractional part, to the right of the decimal point. The precision of a numeric is the total count of significant digits in the whole number, that is, the number of digits to both sides of the decimal point
(Emphasis mine)
So the first number (precision) in the type definition is the total number of digits. The second one is the number of decimal digits.
If you specify numeric(12,6) you have a total of 12 digits and 6 decimal digits, which leaves you only 6 digits for the digits to the left of the decimal. Therefor you need numeric(18,6)

Crystal xi - string numbers together without decimal places

I need to build a text field by stringing 2 numbers together for a barcode.
For example: fld1 is 12345678 and fld2 is 145.99.
fld1 needs to be 9 characters long, zero filled and fld2 needs to be 8 characters long, zero filled.
I need the string to be 01234567800014599
There is 2 step to do. One need concatenation, for this '+' is used to concatenate.
For the leading zero you can use Right function (refer below link)
ToText({table1.fld1},"000000000") + ToText({table1.fld1},"000000000")
or
Right("0000"&{table1.fld2},8) + Right("0000"&{table1.fld2},8)
just check this link :- Padding a fixed number with leading zeros up to a fixed length
Crystal report; Combining rows of data into a single value

how to remove last zero from number in matlab

If I set a variable in Matlab, say var1 = 2.111, after running the script, Matlab returns var1 = 2.1110. I want Matlab to return the original number, with no trailing zero. Anyone know how to do this. Thanks in advance.
By default Matlab displays results in Short fixed decimal format, with 4 digits after the decimal point.
You can change that to various other format such as:
long
Long fixed decimal format, with 15 digits after the decimal point for double values, and 7 digits after the decimal point for single values.
3.141592653589793
shortE
Short scientific notation, with 4 digits after the decimal point.
Integer-valued floating-point numbers with a maximum of 9 digits do not display in scientific notation.
3.1416e+00
longE
Long scientific notation, with 15 digits after the decimal point for double values, and 7 digits after the decimal point for single values.
Integer-valued floating-point numbers with a maximum of 9 digits do not display in scientific notation.
3.141592653589793e+00
shortG
The more compact of short fixed decimal or scientific notation, with 5 digits.
3.1416
longG
The more compact of long fixed decimal or scientific notation, with 15 digits for double values, and 7 digits for single values.
3.14159265358979
shortEng
Short engineering notation, with 4 digits after the decimal point, and an exponent that is a multiple of 3.
3.1416e+000
longEng
Long engineering notation, with 15 significant digits, and an exponent that is a multiple of 3.
3.14159265358979e+000
However I don't think other options are available. If you absolutely want to remove those zeros you would have to cast you result in a string and remove the trailing 0 characters and then display your result as a string and not a number.

printing int with specified nr of digits

I am trying to print out a 5 digit number as follows:
int rdmNr = arc4random()%100000;
NSLog(#"%i",rdmNr);
I always would like to have 5 digit numbers. Example outputs should be:
00001
10544
00555
78801
But with the previous code I would also get 1 or 555 without 0s. I also tried %5i, but the I just get more white spaces.
try
NSLog(#"%05i",rdmNr);
In general, you can specify 2 types of padding for NSLog - filling the required extra characters with spaces (#"%5i") or with leading zeros (#"%05i")
NSLog(#"%05i", rdmNr);
The 5 means that 5 characters should be printed, the 0 means that it should be padded with zeros to the left.
NSLog accepts the same arguments as printf (see here) in addition %# prints an NSString, more info here.
You can also find some common specifiers at Placeholders on Wikipedia