Flat Previous Topic | Next Topic
Stefan
Posted on: 4/9/2013 3:02 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Macro: Calculate HDD Size in MB from entered GB size

Do you want to create new partitions
with exactly n GB but you have to enter this in MB unit
because the Disk Management wants to get MB only?

If yes, this script will aid you.
It calculates the MB size from the entered GB (or TB) size:

Basically it's just a simple math:
n GB = n*1024 MB
n TB = n*1024*1024 MB

But since EmEditor is open anyway,
he can do the math for me:

``````
//Calculate HDD Size in MB from entered GB
//  for creating new partitions in correct wanted size
//    because the Disk Management works with MB only

vInput = prompt("Enter GB size (add a 'T' for TB input) to calculate to MB :", "80");

vInput = vInput.toUpperCase();
vTest =  vInput.replace(/[A-Z ]/g,"");
if(vTest.length < 1){alert("Missing the size?\nUse e.g. 80 for 80GB or 80t for 80TB");quit();}

vInput = vInput.replace(/[A-FH-SU-Z ]/g,"");

if(vInput.indexOf("G") > 0){
vInput = vInput.replace(/[A-Z ]/g, "");
vResult = vInput * 1024;
alert(vInput + " GB = " + vResult + " MB");
}else
if(vInput.indexOf("T") > 0){
vInput = vInput.replace(/[A-Z ]/g, "");
vResult = vInput * 1024 * 1024;
alert(vInput + " TB = " + vResult + " MB");
}else{
vInput = vInput.replace(/[A-Z ]/g, "");
vResult = vInput * 1024;
alert(vInput + " GB = " + vResult + " MB");
}
``````

// 10 GB = 10240 MB
// 80 GB = 81920 MB
// 100 GB = 102400 MB
// 250 GB = 256000 MB
// 300 GB = 307200 MB
// 400 GB = 409600 MB
// 500 GB = 512000 MB
// 555 GB = 568320 MB
//1000 GB = 1024000 MB
//1024 GB = 1048576 MB
// 1 TB = 1048576 MB
// 80 TB = 83886080 MB

 Flat Previous Topic | Next Topic

Subject Poster Date
» Macro: Calculate HDD Size in MB from entered GB size Stefan 4/9/2013 3:02 am

 Register To Post ________________Announcements  - Announcements ________________EmEditor Core  - Questions and Answers about EmEditor Core   - Regular Expressions   - EmEditor Core Enhancement Suggestions   - EmEditor Core Bug Reports ________________Plug-ins  - Questions and Answers about Plug-ins   - Enhancement Suggestions about Plug-ins   - Plug-in Bug Reports ________________Macros  - Questions and Answers about Macros   - Enhancement Suggestions about Macros   - Macro Samples ________________Beta Room  - Beta Version Bug Reports ________________User Comments  - Testimonials ________________Other Topics  - Other Programs   - General