ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Yanrui Li <liyanrui.m2@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Chinese numeral conversion
Date: Wed, 23 Dec 2009 10:05:43 +0800	[thread overview]
Message-ID: <c3f901470912221805n496f60f4i52357d3cae8dfa92@mail.gmail.com> (raw)
In-Reply-To: <c3f901470912221746u5d920a9ve9506088bd767de@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 512 bytes --]

2009/12/23 Yanrui Li <liyanrui.m2@gmail.com>

>
>
> 2009/12/23 Yanrui Li <liyanrui.m2@gmail.com>
>
> Hi Hans,
>>
>> I modified the part of Chinese numeral conversion in core-con.lua script.
>> The attachment is the patch. After many tests as the following I think the
>> patch is right even though it looks dirty.
>
>
> sorry, this function should be:
>
>
sorry again.

I just discovered it is wrong with the numbers biger than 100000. Now I made
a new patch and new output result.

-- 
Best regards,

Li Yanrui

[-- Attachment #1.2: Type: text/html, Size: 1109 bytes --]

[-- Attachment #2: core-con.lua.patch --]
[-- Type: application/octet-stream, Size: 3514 bytes --]

--- /opt/context/tex/texmf-context/tex/context/base/core-con.lua	2009-12-21 15:26:29.000000000 +0800
+++ core-con.lua	2009-12-23 10:02:02.000000000 +0800
@@ -309,7 +309,7 @@
 
 local vector = {
     normal = {
-                [0] = "○",
+                [0] = "〇",
                 [1] = "一",
                 [2] = "二",
                 [3] = "三",
@@ -343,7 +343,7 @@
         [100000000] = "亿",
     },
     all = {
-                [0] = "○",
+                [0] = "〇",
                 [1] = "一",
                 [2] = "二",
                 [3] = "三",
@@ -371,39 +371,56 @@
             break
         elseif n >= 100000000 then
             local m = floor(n/100000000)
-            if m > 1 then result[#result+1] = tochinese(m) end
+            result[#result+1] = tochinese(m,name)
             result[#result+1] = vector[100000000]
+	    local z =  n - m * 100000000
+	    if z > 0 and z < 10000000 then result[#result+1] = vector[0] end
             n = n % 100000000
         elseif n >= 10000000 then
-            result[#result+1] = tochinese(floor(n/10000))
+ 	    local m = floor(n/10000)
+            result[#result+1] = tochinese(m,name)
             result[#result+1] = vector[10000]
+	    local z =  n - m * 10000 
+	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 1000000 then
-            result[#result+1] = tochinese(floor(n/10000))
+	    local m = floor(n/10000)
+            result[#result+1] = tochinese(m,name)
             result[#result+1] = vector[10000]
+	    local z =  n - m * 10000 
+	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 100000 then
-            result[#result+1] = tochinese(floor(n/10000))
+	    local m = floor(n/10000)
+            result[#result+1] = tochinese(m,name)
             result[#result+1] = vector[10000]
+	    local z = n - m * 10000
+	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end	    
             n = n % 10000
         elseif n >= 10000 then
             local m = floor(n/10000)
-            if m > 1 then result[#result+1] = vector[m] end
+            result[#result+1] = vector[m]
             result[#result+1] = vector[10000]
+	    local z =  n - m * 10000
+	    if z > 0 and z < 1000 then result[#result+1] = vector[0] end
             n = n % 10000
         elseif n >= 1000 then
             local m = floor(n/1000)
-            if m > 1 then result[#result+1] = vector[m] end
+            result[#result+1] = vector[m]
             result[#result+1] = vector[1000]
+	    local z =  n - m * 1000
+	    if z > 0 and z < 100 then result[#result+1] = vector[0] end
             n = n % 1000
         elseif n >= 100 then
             local m = floor(n/100)
-            if m > 1 then result[#result+1] = vector[m] end
+            result[#result+1] = vector[m]
             result[#result+1] = vector[100]
+	    local z = n - m * 100
+	    if z > 0 and z < 10 then result[#result+1] = vector[0] end
             n = n % 100
         elseif n >= 10 then
             local m = floor(n/10)
-            if vector[m*10] then
+            if m > 1 and vector[m*10] then
                 result[#result+1] = vector[m*10]
             else
                 result[#result+1] = vector[m]
@@ -415,6 +432,9 @@
             break
         end
     end
+    if (result[1] == vector[1] and result[2] == vector[10]) then
+	result[1] = ""
+    end
     return concat(result)
 end
 

[-- Attachment #3: ch-n.pdf --]
[-- Type: application/pdf, Size: 11136 bytes --]

[-- Attachment #4: Type: text/plain, Size: 486 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

      reply	other threads:[~2009-12-23  2:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-23  1:43 Yanrui Li
2009-12-23  1:46 ` Yanrui Li
2009-12-23  2:05   ` Yanrui Li [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c3f901470912221805n496f60f4i52357d3cae8dfa92@mail.gmail.com \
    --to=liyanrui.m2@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).