■センチ(cm)からインチ(in)へ変換
センチ(cm)からインチ(in)へ変換するには0.3937を乗算すればよい。
1 cm = 0.3937 in
function cm_to_in(n)
{
return n * 0.3937;
}
[目次に戻る]
実際のコード [src/]
■JavaScript (HTML)
<html>
<head>
<title>?Z???`(cm)?????C???`(in)?÷????</title>
<script language="JavaScript" type="text/javascript">
<!--
function cm_to_in(n)
{
return n * 0.3937;
}
--></script>
</head>
<body>
<h1>?Z???`(cm)?????C???`(in)?÷????</h1>
<form>
?@?@?@?@?Z???`?F<input type="text" name="cm"><br>
?C???`?i??? ?j?F<input type="text" name="inch"><br>
<input type="button" value="????????" onClick="this.form.inch.value=cm_to_in(eval(this.form.cm.value))"
</form>
</body>
</html>
■JavaScript (Photoshop CS)
n = parseFloat(prompt("cm value = ",1));
n = n * 0.3937;
alert(n);
■Python
import sys
n = float(sys.argv[1])
print n * 0.3937
■Perl
#!/usr/bin/perl
$n = $ARGV[0];
$n = $n * 0.3937;
print "$n\n";
■Ruby
#!/usr/bin/ruby
n = $*[0].to_f * 0.3937
print n,"\n"
■C
#include <stdio.h>
int main(int argc, char *argv[])
{
double n;
n = atoi(argv[1]);
printf("%f\n",n*0.3937);
}
■Java
import java.io.*;
class unitcalc{
public static void main(String args[]){
double n=Double.valueOf(args[0]).doubleValue();
System.out.println(n * 0.3937);
}
}
■AppleScript
set result to display dialog "cm = " default answer "1"
set n to text returned of result
set n to 0.3937 * n
display dialog n
■awk【別ファイルデータを読み込んで処理】
#!/usr/bin/awk -f
{
n = $0;
}
END {
print "result =" , n * 0.3937
}
■Microsoft Excel 2004 (MacOS X)
=A2*0.3937