変換

Fahrenheitなどの値をCelsiusまたはCelsiusにFahreinheit度に自動的に変換します。

例3-1摂氏から華氏への変換

//given temperature in C, convert to F and return converted value

var fahrenheit;
fahrenheit = (celsius * (9/5)) + 32;
return Number(fahrenheit);

例3-2インライン計算を使用した摂氏から華氏への変換(簡略化)

//given temperature in C, returning converted value to F using inline calculation

return (tempc * (9/5)) + 32;

例3-3インライン計算を使用した華氏から摂氏への変換

//given temperature in F, returning converted value to C using inline calculation

return (tempf - 32) * 5/9);