換算
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);
親トピック: 一般的な式