Temperature Table Generator

I was calculating temperatures one day trying to figure out which heatsink/fan I should get for my computer processor and got tired of converting Celcius to Fahrenheit (and visa-versa) by hand. So I thought I would build a script to take the drudgery out of it. This JavaScript will generate temperature conversion tables using parameters you specify.




Over 2000+ free Javascript
at JavaScriptBank.com Website
Sampled by JavaScriptBank.com View Examples below:



Below are two examples of "hard-coded" tables that show the data in rows.


Temperature Table 1: From 0°C to 34&degC in 2 degree increments with 2 digit precision.



Temperature Table 2: From 32°F to 90°F in 3 degree increments with 1 digit precision.




The code used to create table #1 looks like this:

<script language="javascript">
document.write(writeRowTempC(0,34,2,2));
</script>


The code used to create table #2 looks like this:

<script language="javascript">
document.write(writeRowTempF(32,90,3,1));
</script>





The script also allows you to create the tables in column form as well. See the two examples below.

Temperature Table 3
From 20°C to 40&degC in 2 degree increments with 2 digit precision.

Temperature Table 4
From 30°F to 80°F in 5 degree increments with 3 digit precision.



The code used to create table #3 looks like this:

<script language="javascript">
document.write(writeColTempC(20,40,2,2));
</script>


The code used to create table #4 looks like this:

<script language="javascript">
document.write(writeColTempF(30,80,5,3));
</script>





As you can see, it isn't very difficult to use the scripts.

If you know a little about Javascript, you can see the functions simply return a string containing the generated HTML code. So, you can use it like I have above, or you can get a bit fancier and make the tables dynamic. See the example below.

Note: I did not "bullet-proof" this part by checking for proper user input. So, if you enter garbage data, you'll get an error. And, this part of the script will not work in Netscape prior to v6.0:

Convert °F to °C
Enter starting
Temperature

Enter ending
Temperature

Enter degree
increments

Enter digit
precision


(Enter some values above and click the button.)



The script to accomplish the above is a bit more detailed; you can view the source of this page if you are really interested.




Incidentally, there is another function that you may find useful called roundFill( n , p ). It accepts two arguments: the number to round (n) and the precision value (p).

The function will round the fractional part of the number to the precision value. It also adds necessary zeros to the end of the number to force the level of precision you specified. So, even if a number has no fractional part, it will add zeros after the decimal point as necessary.




Instructions:



To make the script work, you'll need the functions that create the tables. Where you put the code to actually write them out is up to you. Look at the code for examples 1 to 4 for help on that.

Recap: There are 4 functions you can use to make the tables:
Then, there's the roundFill() function I talked about earlier, which the four functions above use.


Copy and paste the following script in the HEAD section of your page:
Select all...


Over 2000+ free Javascript
at JavaScriptBank.com Website