-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
add BAHTTEXT and DOLLAR with their test files #2148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zhuyanhuazhuyanhua
wants to merge
1
commit into
qax-os:master
Choose a base branch
from
zhuyanhuazhuyanhua:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18842,3 +18842,93 @@ func (fn *formulaFuncs) DISPIMG(argsList *list.List) formulaArg { | |
} | ||
return argsList.Front().Value.(formulaArg) | ||
} | ||
|
||
// 定义泰语数字到泰语字符的映射 | ||
var thaiDigits = map[int]string{0: "ศูนย์", 1: "หนึ่ง", 2: "สอง", 3: "สาม", 4: "สี่", 5: "ห้า", 6: "หก", 7: "เจ็ด", 8: "แปด", 9: "เก้า"} | ||
|
||
// 定义泰语数位单位 | ||
var thaiUnits = []string{"", "สิบ", "ร้อย", "พัน", "หมื่น", "แสน", "ล้าน"} | ||
|
||
// numToThaiText 将数字转换为泰语数字文本 | ||
func numToThaiText(num int) string { | ||
if num == 0 { | ||
return thaiDigits[0] | ||
} | ||
var result string | ||
var pos int | ||
for num > 0 { | ||
digit := num % 10 | ||
if digit > 0 { | ||
if pos == 1 && digit == 2 { | ||
result = "ยี่" + thaiUnits[pos] + result | ||
} else if pos == 1 && digit == 1 { | ||
result = thaiUnits[pos] + result | ||
} else if pos == 0 && num > 10 && digit == 1 { | ||
result = "เอ็ด" + result | ||
} else { | ||
result = thaiDigits[digit] + thaiUnits[pos] + result | ||
} | ||
} | ||
num /= 10 | ||
pos++ | ||
} | ||
return result | ||
} | ||
|
||
// func (fn *formulaFuncs) BAHTTEXT 将数字转换为泰铢货币格式的文本 | ||
func (fn *formulaFuncs) BAHTTEXT(argsList *list.List) formulaArg { | ||
// 定义错误信息变量 | ||
const ( | ||
errNoArgMsg = "BAHTTEXT requires at least 1 argument" | ||
errTooManyArgs = "BAHTTEXT requires 1 argument" | ||
) | ||
|
||
// 验证参数数量 | ||
if argsList.Len() == 0 { | ||
return newErrorFormulaArg(formulaErrorVALUE, errNoArgMsg) | ||
} | ||
if argsList.Len() > 1 { | ||
return newErrorFormulaArg(formulaErrorVALUE, errTooManyArgs) | ||
} | ||
|
||
// 提取并转换参数为数字 | ||
numArg := argsList.Front().Value.(formulaArg) | ||
num := numArg.ToNumber() | ||
|
||
// 检查转换结果是否为数字类型 | ||
if num.Type != ArgNumber { | ||
return num | ||
} | ||
|
||
// 分离整数部分和小数部分 | ||
integerPart := int(num.Number) | ||
decimalPart := int((num.Number - float64(integerPart)) * 100) | ||
|
||
// 定义泰语货币单位变量 | ||
const ( | ||
bahtUnit = "บาท" | ||
satangUnit = "สตางค์" | ||
zeroBahtMsg = "ศูนย์บาทถ้วน" | ||
) | ||
|
||
// 转换整数部分为泰语文本 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Duplicate comment found; you can remove the redundant line to keep comments concise. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
// 转换整数部分为泰语文本 | ||
var integerText string | ||
if integerPart > 0 { | ||
integerText = numToThaiText(integerPart) + bahtUnit | ||
} | ||
|
||
// 转换小数部分为泰语文本 | ||
var decimalText string | ||
if decimalPart > 0 { | ||
decimalText = numToThaiText(decimalPart) + satangUnit | ||
} | ||
|
||
// 组合最终结果 | ||
result := integerText + decimalText | ||
if result == "" { | ||
result = zeroBahtMsg | ||
} | ||
|
||
return newStringFormulaArg(result) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'too many args' error message is ambiguous. Consider changing it to "BAHTTEXT requires exactly 1 argument" for clarity.
Copilot uses AI. Check for mistakes.