Script to convert Gigabyte (GB) to MegaByte (MB)

Dazler
Mega Sage

Hi,

 

I am working on a Flow Designer for using the Terraform third party API.  One of the requirements is to pass the value on one of the Catalog Item fields to the Flow.  The field is asking for the user to "Provide Drive Size in GBs".  Unfortunately, the Terraform needs that value in Megabytes.

 

I need to convert whatever Gigabytes the user provides into Megabytes.  Does anyone have a script that will help me to convert this?

1 ACCEPTED SOLUTION

Well this should suffice

var gb = 1; // take this as input form variable or field
var mb = parseInt(gb)*1024;
-Anurag

View solution in original post

4 REPLIES 4

Tony Chatfield1
Kilo Patron

Hi, an exact script is dependent on a number of values that are not included in your post, required final format - decimal or binary; The format of your source data string\text, or some sort of numerical value.
Javascript will normally recognize and process string representations of numerical values correctly if you are using mathematical formula,
if it does not you can use one of the javascript number methods to convert the string to a numerical value before your calculation. eg parseInt() or parseFloat()

JavaScript Number Reference (w3schools.com)

 

 

Hi @Tony Chatfield1 

 

I know that 1 GB equals 1024 MB.  So if the user puts 8 GB in the string text field (which is set to only accept numbers), I need to multiple that number by 1024 to get the MB number. 

 

I just need a little help with script.

Well this should suffice

var gb = 1; // take this as input form variable or field
var mb = parseInt(gb)*1024;
-Anurag

Thank you, @Anurag Tripathi