ASP: Convert Temperature (Fahrenheit & Celcius)


Introduction

Author: Martin Warning
Year: 2008
License: Free

These functions are useful if you have temperature data in one temperature system and need to convert them to another.

Code

Languages: The following code is an example function to convert Fahrenheit to Celsius:
<%
' Function to convert Fahrenheit to Celsius

Function fncFahrenheitToCelsius(intF)

	If isNumeric(intF) Then
		fncFahrenheitToCelsius = formatNumber((5/9)*(intF-32),2) & " °C"
	End If

End Function
%>

This code will only convert a date send to it to a RSS compatible date. You would call this function like fncRSSDate(Now()) to get the RSS variant of in this case the current time (at page load).


The following code is an example function to convert Celsius to Fahrenheit:
<%
' Function to convert Celsius to Fahrenheit

Function fncCelsiusToFahrenheit(intC)

	If isNumeric(intC) Then
		fncCelsiusToFahrenheit = formatNumber(((9*intC)/5) + 32,2) & " °F"
	End If

End Function
%>
The formatNumber allows us to limit the ammount of decimals shown. It takes 2 values, the first being the number you want to modify and the second value the ammount of decimal places that should be shown, which is 2 in the examples case.


Pinternet.net: The world of beer on the Internet
Printed from: http://flyinglowlander.com/ (5/20/2012)
© FlyingLowander.com 2006 - 2012

Visit http://flyinglowlander.com for more XHTML, CSS, ASP and JavaScript examples, templates and tutorials.