Wednesday, 8 August 2018

Common Measurement Conversions In PHP

One of the tricky things about being a web developer is that you are sometimes forced to accommodate visitors that use different measurement systems and formats. Currency symbols, date formats and measurement systems; all of them can differ from one user to the next. The following PHP code snippets will help you to convert between some of the most common measurements (most notably, those found in the Imperial System and the Metric System).

Kilograms to Pounds

As you can see, it’s as simple as multiplying the number of KG by 2.20462. In fact, you’ll find that most of the subsequent examples are just as straight-forward.

Pounds to Kilograms

While Pounds (lb) is a popular measurement for weight in the United States; in Europe, they tend to use Kilograms:

Stone to Kilograms

To convert Stone into KG, multiply by 6.35029:

Kilometres to Miles

KM x 0.621371 = Miles

Miles to Kilometres

Miles x 1.60934 = KM

Pounds to Stone

Pounds x 0.0714286 = Stone

Yards to Meters

Yards x 0.9144 = Meters

Centimetres to Meters

There are 100 centimetres in a meter:

Meters to Centimetres

And vice versa:

Centimetres to Inches

There are 39.3700787 inches in a meter:

Meters to Miles

Meters x 0.000621371 = Miles

Inches to Centimetres

Centimetres = Inches x 2.54

Fahrenheit to Celsius

As you can see, converting Fahrenheit to Celsius is not as simple as the conversions shown above:

Celsius to Fahrenheit

Converting Celsius into Fahrenheit isn’t exactly straight forward either:

0 comments:

Post a Comment