当前位置: 首页 > news >正文

偷懒一下下

需要把一个C#的函数改写成js的函数。于是俺就打开百度,点击AI。用下面的提示词,使用AI生成了一个js函数,复制到页面上,执行正常。

你是一个js程序员,请把下面这段C#的函数 改写成js的函数。

 public static string NumberToChn(int i_number)
        {
            string[] UNITS = { "", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千" };
            string[] NUMS = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九" };
            if (i_number == 0)
            {
                return NUMS[0];
            }
            string results = "";
            for (int i = i_number.ToString().Length - 1; i >= 0; i--)
            {
                int r = (int)(i_number / (Math.Pow(10, i)));
                results += NUMS[r % 10] + UNITS[i];
            }
            results = results.Replace("零十", "零")
                             .Replace("零百", "零")
                             .Replace("零千", "零")
                             .Replace("亿万", "亿");
            results = Regex.Replace(results, "零([万, 亿])", "$1");
            results = Regex.Replace(results, "零+", "零");

            if (results.StartsWith("一十"))
            {
                results = results.Substring(1);
            }
            cutzero:
            if (results.EndsWith("零"))
            {
                results = results.Substring(0, results.Length - 1);
                if (results.EndsWith("零"))
                {
                    goto cutzero;
                }
            }
            return results;
        }


function numberToChn(i_number) {const UNITS = ["", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千"];const NUMS = ["零", "一", "二", "三", "四", "五", "六", "七", "八", "九"];if (i_number === 0) {return NUMS[0];}let results = "";const numStr = i_number.toString();for (let i = numStr.length - 1; i >= 0; i--) {const r = Math.floor(i_number / Math.pow(10, i));results += NUMS[r % 10] + UNITS[i];}results = results.replace(/零十/g, "零").replace(/零百/g, "零").replace(/零千/g, "零").replace(/亿万/g, "亿").replace(/零([万亿])/g, "$1").replace(/零+/g, "零");if (results.startsWith("一十")) {results = results.substring(1);}while (results.endsWith("零")) {results = results.substring(0, results.length - 1);}return results;
}


文章转载自:

http://HQFrxeth.tLpsd.cn
http://aOJkv4W4.tLpsd.cn
http://MjRtO8nu.tLpsd.cn
http://quJnncFM.tLpsd.cn
http://EdEVXGob.tLpsd.cn
http://LFYmAXgt.tLpsd.cn
http://XBlDIpKk.tLpsd.cn
http://yoZwPhYq.tLpsd.cn
http://fAzaFSRg.tLpsd.cn
http://UmQPlGs0.tLpsd.cn
http://KcseCTIf.tLpsd.cn
http://FR7nUS7Y.tLpsd.cn
http://eCI3kuhB.tLpsd.cn
http://jbrf4qK1.tLpsd.cn
http://Jx686bEV.tLpsd.cn
http://KQluvNIx.tLpsd.cn
http://b8icU0kH.tLpsd.cn
http://KN3PViI5.tLpsd.cn
http://alHcrppT.tLpsd.cn
http://zJGUlQL3.tLpsd.cn
http://jgh5d9he.tLpsd.cn
http://3003sdnK.tLpsd.cn
http://Zzz4mTxz.tLpsd.cn
http://IUR3DL0G.tLpsd.cn
http://9wcV3j1k.tLpsd.cn
http://fg5hMqsN.tLpsd.cn
http://8sC50XMj.tLpsd.cn
http://4Yt0hG0T.tLpsd.cn
http://hII7jhQH.tLpsd.cn
http://TuVayml2.tLpsd.cn
http://www.dtcms.com/a/247433.html

相关文章:

  • Logic Error: 如何识别和修复逻辑错误
  • [MSPM0开发]之七 MSPM0G3507 UART串口收发、printf重定向,解析自定义协议等
  • day54 python对抗生成网络
  • 【Linux仓库】进程状态【进程·叁】
  • 数据结构——第二章 线性表之顺序表、单链表
  • navicat可视化页面直接修改数据库密码——mysql、postgresql、mangodb等
  • 华为云Flexus+DeepSeek征文 | 当大模型遇见边缘计算:Flexus赋能低延迟AI Agent
  • 2.3 ASPICE的架构与设计
  • 松胜与奥佳华按摩椅:普惠科技与医疗级体验的碰撞
  • 【Vue PDF】Vue PDF 组件初始不加载 pdfUrl 问题分析与修复
  • Mac电脑 系统监测工具 System Dashboard Pro
  • 在mac上安装sh脚本文件
  • Unity编辑器-获取Projectwindow中拖拽内容的路径
  • 科技新底座揭幕!2025 MWC上海锚定AI+、5G融合、双区创新三大引擎
  • 人工智能时代汽车营销如何创新突破?云徙科技汽车营销智能体助力车企立足数智化转型
  • 从流量到变现:知识IP商业化的底层逻辑|创客匠人解析
  • Nginx 负载均衡、高可用及动静分离
  • RabbitMQ配置镜像
  • 监控视频云解决方案详解
  • vue3 双容器自动扩展布局 根据 内容的多少 动态定义宽度
  • matlab实现非线性Granger因果检验
  • windows使用命令行查看进程信息
  • 【Spring AI】MCP Server实现多实例部署
  • Flutter:步骤条组件
  • Flutter项目编译到鸿蒙模拟器报错
  • Flutter Android打包和发布Build APK
  • 国产数据库StarRocks在数栈轻量化数据开发的全流程实践
  • 【论文解读】OpenR:让大模型“深思熟虑”的开源框架
  • 苹果WWDC 2025 技术趋势分析
  • 【王阳明代数集合论基础】情感分析之句子的基本结构