@REM 数値の単位を変更する
@echo off
REM #jww
REM #cd
REM #zz
REM #zc
REM #h3
REM #hc文字を範囲選択してください
REM #k3桁毎区切文字の有無 |1)有(L)|2)無(R)| /_/a
REM #c区切文字の入力 無指定 : コンマ( , ) /_/b
REM #c小数点以下有効桁数 無指定 : 0 /_/c
REM #e
copy jwc_temp.txt temp.txt > nul
ruby -Ks 単位変更.rb temp.txt %1 %2 %3> jwc_temp.txt
puts "hd";$kugiri="1";$moji="\,";$keta=0
while ARGV.size > 1
case argument=ARGV.pop
when /\/a/
$kugiri=argument[2..-1]
when /\/b/
$moji=argument[2..-1]
if argument[2..-1]==""
$moji="\s"
end
when /\/c/
$keta=argument[2..-1]
end
end
def tani_henko(s)
hash1={"0"=>"0","1"=>"1","2"=>"2","3"=>"3","4"=>"4","5"=>"5",
"6"=>"6","7"=>"7","8"=>"8","9"=>"9","."=>".",","=>",",
"+"=>"+","−"=>"-","__"=>"_"," "=>" "}
if s=~/^\d|^-/ or hash1.key?(s[0,2])
s.tr!("\_\,\s, ","")
a=s.split('')
if a[0].size==2
0.upto(a.size-1){|i|a[i]=hash1[a[i]]}
end
a2=ika(((a.join).to_f/1000).to_s)
if a.include?(nil)!=true && a.join=~/^\d+\.*\d*$/
hash2=hash1.invert
s.split('')[0].size==2 ?
a3=(a2.split('')).collect{|item|hash2[item]}.join : a3=a2
if $kugiri=="1"
return conma(a3,3,$moji)
else
return a3
end
else
return s
end
else
return s
end
end
def ika(x)
if $keta=="0"
a=((x.to_f).round).to_s
return a
else
keta=$keta.to_i
a=(((x.to_f)*(10**keta)).round/(10**keta).to_f).to_s
if a=~ /.0$/
a=(a.to_i).to_s
end
return a
end
end
def conma(s,i,w)
hash1={"0"=>"0","1"=>"1","2"=>"2","3"=>"3","4"=>"4","5"=>"5",
"6"=>"6","7"=>"7","8"=>"8","9"=>"9","."=>".",","=>",",
"+"=>"+","−"=>"-","__"=>"_"," "=>" "}
if s=~/^\d|^-/ or hash1.key?(s[0,2])
if s=~/\./ or s=~/./
moji=$`
ika=$&+$'
else
moji=s
ika=""
end
moji.tr!("#{w}\_\,\s,, ","")
a=moji.split('')
if a[0,1].size==2
0.upto(a.size-1){|i|a[i]=hash1[a[i]]}
end
a.reverse!
n=0;b=[]
a.each{|item|n!=0 && n%(i.to_i)==0 ? b<<(item+w):b<<(item)
n+=1}
if hash1.key?(s[0])
hash2=hash1.invert
0.upto(b.size-1){|i|b[i]=hash2[b[i]]}
end
return(b.reverse.join+ika)
else
return s
end
end
while ARGF.gets
xy=split
if xy[0]=~/^hq/
elsif xy[0]=~/^ch|^cs/
if $_=~/\"/
moji=$'.chop
puts $`+$&+tani_henko(moji)
end
else
print $_
end
end
def ika(x)
keta=$keta.to_i
a=(((x.to_f)*(10**keta)).round/(10**keta).to_f).to_s
if keta==0
a=(a.to_i).to_s
else
if a=~ /\./
size=$'.split('').size
if keta>size
a=a+"0"*(keta-size)
end
end
end
return a
end