Frontier: adding narrative temperature conversion my browser window is at least this wide
Locations of visitors to this page

find on this site
be notified of website changes?

lawyers!

 

Frontier

Using Frontier

Extending Frontier

adding favicons

migrating websites

Using CSS

Fixing Radio 8.1

Fixing Frontier 5

nextPrev broken

err log sans timestamp

temperature conversion

our WebRing

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

Frontier: adding narrative temperature conversion

Tuesday 26 July 2005

It's frustrating being in a metric-phobic country. Whenever we travel I find that metric temperatures just make sense. Readers from all over visit these pages, and to make life just a wee bit easier, I wrote a small script to provide temperatures in my narrative in both Farenheit and Celcius, and in the same precision. Here's some examples of the script in action:

98° F (36° C)
98.6° F (37.0° C)
98.6121° F (37.0067° C)

Bowing to the logic that the contextually appropriate temperature scale should appear first, with the conversion following, I require only a value an a scale, so an American can write I have a fever; it's 98.6° F (37.0° C), whereas pretty much everyone else would say ... 37° C (98° F).

The function looks like this

{temp(98.6, "F")}

and here's how it's implemented:

on temp( value, scale = "F" ) {
	«
	«Do the conversion mathematics
	«
	local {
		result  = 0.0;
		oldScale, newScale, h, answer, precision};
	if ( scale == "f" ) {
		scale = "F"};
	if ( scale == "F") {
		result = (value - 32) * (5.0 / 9.0);
		oldScale = "F";
		newScale = "C"}
	else {
		result = (value * (9.0 / 5.0)) + 32;
		oldScale = "C";
		newScale = "F"};
	«
	«Generate output that has at most the number of decimal places as the input.
	«
	dotPosition = string.PatternMatch( ".", value );
	if ( dotPosition == 0 ) {
		precision = -1}
	else {
		precision = string.length(value) - dotPosition};
	answer = string.mid( result, 0, string.patternMatch( ".", result ) + precision );
	h = value + "° " + oldScale + " (" + answer + "° " + newScale + ")";
	return( h )};

I hope you have as much fun with this as I do. It's nice to strike a blow for learning "that other system"...

This page is part of the Userland Frontier WebRing. webring List all this webring's pages; visit another page; add your page to this webring.

Have you found errors nontrivial or marginal, factual, analytical and illogical, arithmetical, temporal, or even typographical? Please let me know; drop me email. Thanks!
 

What's New?  |  Kilts! Kilts! Kilts!  |  Travel  |  Burning Man
Search  |  Site Map  |  Macintosh  |  San Francisco  |  Technology  |  CU-SeeMe
This page is copyrighted 1993-2006 by Michael 'Mickey' Sattler, some rights reserved via the Creative Commons License. Questions and comments? Send email to the Geek Times Webmaster. (Domain and web content hosting at 1and1.)