Calculating all number from a text file (division) - text

I have a file or a text which contains huge numbers. This is how it looks:
2622256647732477952, 3146707977278973440, 3776049572734768128, 4531259487281721344, 5437511384738065408, 6525013661685678080, 7830016394022813696, 9396019672827375616, 11275223607392849920, 13530268328871419904,
I want to divide every number by the factor of 100. Is there any fast way to do this? notepadd++ maybe? or any 3rd party editor which is able to do such stuff?
It's around 1000 numbers would be pretty time consuming to do this manually.

All the numbers seem to be integers. If that is true, and if they are all above 100 (the divisor), why not just use a regular expression to insert a decimal point in every number.
In Notepad++ try:
Search string: (\d+)(\d{2})
Replace string: $1.$2
Check "Regular expression" box and hit "Replace all".
Edit:
In the special case you mention in your comment, where the decimals should just be disregarded, you can simply use (\d+)\d{2} as search string and $1 as the replace string. Note that the result won't be rounded to the nearest integer though (11189 should become 112 really, but you'll get 111).
Other options include importing the string into Excel or other spreadsheet software and use a formula in there, writing a javascript snippet to split the string up and divide each number etc.

Related

Why when I use text to column Excel changes my numbers

For example I have this line right here:
-2.7769,-5.6967,5.9179,0.37671,1
When I convert text to column using as delimiter comma in preview I see the result just right:
-2.7769 -5.6967 5.9179 0.37671 1
But when I press confirm I get this:
-27.769 -56.967 59.179 0.37671 1
How can I stop it from doing that and get the desired outcome?
I tried to make a line separated with commas into columns using the text to column feature from excel but I didn't get the result I was hoping for.
I don't know the entire solution, but I clearly see that you are mixing up decimal delimiter and thousand delimiter:
I guess that you mean "-2.7769" meaning "minus two, followed by a decimal separator, followed by .7769 (a number between zero and one)", but what your computer understand is: "minus twenty-seven thousand, seven hundred and sixty-nine, but the user has put the thousand separator at the wrong place. I will correct this."
In order to check whether or not your Excel is using a thousand separator, you can ask a random cell's formatting (right-click, choose "Format cells"): the "Use 1000 Separator (,)" checkbox in the "Number" chapter should be unchecked, as in this screenshot:

How to use =LEFT and =LEN function with scientific notation in Excel VBA?

I'm trying to write an Excel macro using VBA that will return only the first 5 numbers in a cell when the length of that cell exceeds 20. The field normally returns 15-digit alphanumeric results (which I need to leave alone) but in certain exceptions will return a 5-digit number with a multitude of zeroes following it (1234500000000000000000000...) which Excel converts into scientific notation (1.2345E+160). I am able to convert the cells to numbers instead of scientific notation and view the whole number.
I've tried to use code such as =IF(LEN(A1)>20,LEFT(A1,5),A1) and it just returns 1.2345E+160. Even though the whole number is displaying, Excel still thinks the cell length is 11 and won't display the first 5 digits.
I've also tried lines such as =IF(A1="E",LEFT(A1,6),A1) thinking it would detect the E, return 1.2345, and I could just remove the decimal points, but that didn't work either (it just returns the original 1.2345E+160).
I got the same results whether the cell was formatted as number or text. Is there a way around this?
Thank you for your time!
You are trying to use string manipulation on a number. Instead use math:
=A1/1E+160
If you do actually want to treat this thing as text, understand that the underlying value being stored is your 12345000000000000... and there is no decimal point in that thing. So you'll have to convert to text and add the decimal:
=LEFT(TEXT(A1,"0"), 1) & "." & MID(TEXT(A1,"0"), 2, 4)
But that's pretty ugly. I would just stick with math.

Decimal number in string-data-type with large amount of decimals always interpreted as large integer (regional decimal separator issue)

Background: I'm receiving data for my Excel application from an API in JSON format. For this matter I'm receiving numerical values as a string, as everything sent in JSON naturally is a text format - and so does VBA also interpret it. As I'm located in Denmark, using a different decimal separator than the native on in Excel (my Danish version utilizes , as separator rather than .).
Case:
This is causing quite a bit of trouble as Excel interprets this as a thousand-separator when converting the string to a number.
Searching for answers I've found that the best solution, normally, is to convert the string to double when using VBA, utilizing CDbl(string to convert to number).
This usually is the case, but in my case I'm receiving a number with a lot of decimals such as: "9.300000190734863".
When doing a CDbl("9.300000190734863") this results in a very large integer: 9,30000019073486E+15
Also, I don't think utilizing a replace() approach is feasible in my case as I might also have data that uses both decimal- and thousand separators at the same time, making my results prone to replacement errors.
However, inserting the string value directly into a cell within Excel converts the number correctly to 9,30000019073486 in my case.
Question: Can it be right that there's no way to mimic, or tap into, this functionality that Excel obviously is using when inserting the string into a cell?
I've searched for quite some time now, and I haven't found any solution other than the obvious: inserting the value into a cell. The problem here is that it's giving me some performance overhead which I would rather avoid.
You can swap the positions of the periods and commas in your input prior to casting as a double, in three steps:
Replace commas with 'X' (or some other value that won't appear in your data)
Replace periods with commas
Replace 'X' with periods

Number representation by Excel

I'm building a VBA program on Excel 2007 inputing long string of numbers (UPC). Now, the program usually works fine, but sometimes the number string seems to be converted to scientific notation and I want to avoid this, since I then VLook them up.
So, I'd like to treat a textbox input as an exact string. No scientific notation, no number interpretation.
On a related side, this one really gets weird. I have two exact UPC : both yield the same value (as far as I or any text editor can tell), yet one of the value gives a successful Vlookup, the other does not.
Anybody has suggestions on this one? Thanks for your time.
Long strings that look like numbers can be a pain in Excel. If you're not doing any math on the "number", it should really be treated as text. As you've discovered, when you want to force Excel to treat something as a string, precede it with an apostrophe.
There are a couple of common problems with VLOOKUP. The one you found, extra whitespace, can be avoided by using a formula such as
=VLOOKUP(TRIM(A1),B1:C:100,2,FALSE)
The TRIM function will remove those extraneous spaces. The other common problem with VLOOKUP is that one argument is a string and the other is a number. I run into this one a lot with imported data. You can use the TEXT function to do the VLOOKUP without having to change the raw data
=VLOOKUP(TEXT(A1,"00000"),B1:C100,2,FALSE)
will convert A1 to a five digit string before it tries to look it up in column B. And, of course, if your data is a real mess, you may need
=VLOOKUP(TEXT(TRIM(A1),"00000"),B1:C100,2,FALSE)

Converting various file sizes to bytes

I have a column of "file sizes" that has been output poorly, as in it's not consistent. For example values may be, "4GB", "32 MB", "320 KB", "932 bytes", etc. I need to convert these all to a standard value so that I can add them up for a report.
Consider this approach
pick one display format. Perhaps choose bytes.
For each cell:
determine its scale. This would likely involve string parsing, looking for "ends with" some valid range of possibilities : "bytes", "kb", "mb", "gb", "kilobytes", "gigabytes". Convert to lower case first, to ensure sanity. Consider misspellings as well!
extract the number. Use a variation of this VBA numeric regex to extract out the numbers. Watch out for decimals!
your output will be (the number) * (the scale in bytes)
Here's a very unsophisticated answer - but it might make this a very quick fix for you, if exact byte counts are not all important. Just do a simple text search and replace.
Replace "KB" (and "kilobytes" and other variations) with "000", "MB" with "000000" and "GB" with "000000000". "bytes" you replace with "". Then convert the cell/column type to numeric.
It won't be as easy if the values are given with decimals ("4.32 MB"), but your examples should work fine.
I would say you have two options:
1: require that all this data be in units of bytes (probably not feasible if the data already exists)
2: use a regex to separate the number from the unit, then use a switch statement (or loop or whatever you like) to perform the correct multiplications to get the number in bytes (probably the easier of the two).
edit :
the regex would look something like this :
(\d*) *(.*)
This will capture the numbers and units separately and ignore any whitespace between the two (you will still need to trim the input to the regex, as preceding and proceeding whitespace can cause some grief).
Bytes, kilobytes, megabytes, etc. are all metric units. Just pick a standard unit for your report (say, megabytes), and multiply or divide values given in different units to get the values you need.

Resources