Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
Conversion for GB to MB in js

I am trying to add a conversation logic for converting 1 GB to value 1000; 2.5 GB to value 2500; 50 MB to value 50; 1 MB to value 1 and so on using javascript.

I tried adding logic but it is comprising multiple if else.

var bw;
var value;
if (bw.toUpperCase() == '1 GB' || bw.toUpperCase() == '1 GBPS')
{
  value = 1000;
}
else if (bw.toUpperCase() == '2.5 GB' || bw.toUpperCase() == '2.5 GBPS')
{
  value = 2500;
}

and so on for MB. The only values that will come are GB or MB. No kb or bytes.

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

One option is:

let units = { GB: 1000, GBPS: 1000, ... };
let [a, b] = yourString.split(' ');
let value = +a * units[b];
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!