def self.num_to_text(num)
ntt=num.to_s ttn=” c=0 j=’0123456789’
while c<=(ntt.length-1) if ntt[c]==j[1] if c==(ntt.length-1)&& ntt.length>1 one=’เอ็ด’ else one=’หนึ่ง’ end ttn=ttn+one end
if ntt[c]==j[2]
if c==(ntt.length-2)&& ntt.length>1
two='ยี่'
else
two='สอง'
end
ttn=ttn+two
end
if ntt[c]==j[3]
ttn=ttn+'สาม'
end
if ntt[c]==j[4]
ttn=ttn+'สี่'
end
if ntt[c]==j[5]
ttn=ttn+'ห้า'
end
if ntt[c]==j[6]
ttn=ttn+'หก'
end
if ntt[c]==j[7]
ttn=ttn+'เจ็ด'
end
if ntt[c]==j[8]
ttn=ttn+'แปด'
end
if ntt[c]==j[9]
ttn=ttn+'เก้า'
end
if ntt.length-c-1==6 || ntt.length-c-1==12 || ntt.length-c-1==18
ttn=ttn+'ล้าน'
end
if ntt[c]!=j[0]
if ntt.length-c-1==5 || ntt.length-c-1==11 || ntt.length-c-1==17
ttn=ttn+'แสน'
end
if ntt.length-c-1==4 || ntt.length-c-1==10 || ntt.length-c-1==16
ttn=ttn+'หมื่น'
end
if ntt.length-c-1==3 || ntt.length-c-1==9 || ntt.length-c-1==15
ttn=ttn+'พัน'
end
if ntt.length-c-1==2 || ntt.length-c-1==8 || ntt.length-c-1==14
ttn=ttn+'ร้อย'
end
if ntt.length-c-1==1 || ntt.length-c-1==7 || ntt.length-c-1==13
ttn=ttn+'สิบ'
end
end
c=c+1 end
return ttn end
กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น
แล้วอันนี้ใส่ comma ให้กับตัวเลข ทำเอง แบบ งง งง
def self.commas(x) str = x.to_s.reverse str.gsub!(/([0-9]{3})/,”\1,”) str.gsub(/,$/,”“).reverse end
ทำไม พี่ ไม่ โพสให้ไวกว่านี้ครับ ผมเขียนสายถึก ไปเรียบร้อยแล้วครับยาวเป็นพรืดเลยครับ ของผมขอฝากตัวด้วยนะครับ แถมคอมม่าให้อีกตัวครับครับ
code
post code สวยงามใช้ blockcode :-) http://blog.vee-u.com/2008/02/17/blockcode/
เอามั่ง ๆ
ไอเดียคือ ไล่อ่านค่าจากหลังสุด โดนทู่ซี่ใส่ “ล้าน” เข้าไปที่หลักหน่วย เพื่อให้สามารถ ใช้ TPOS[key%6] ในการไล่ใส่ค่าประจำหน่วยได้ แล้วค่อยไปตัดล้านที่มันเกินมาตรงหลักหน่วยออก ที่เหลือก็ง่าย ๆ ไม่มีอะไร อ่านเข้ามา,เช็คตำแหน่ง แล้ว เก็บค่าคำอ่านที่เหมาะสม ไปเรื่อยๆ
ของคุณ taiko_gogo ดูสั้นง่าย เข้าใจดีครับ