当前位置: 首页 > 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;
}

相关文章:

  • 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 双容器自动扩展布局 根据 内容的多少 动态定义宽度
  • 高邑做网站/内蒙古seo
  • 做网站java好还是php好/惠州seo按天计费
  • 做网站需要些什么/官方正版清理优化工具
  • 企业网站流量怎么做/站长工具seo综合查询下载
  • 济南网站建设需要多少钱/百度广告联盟app
  • wap网站建设是什么/外链平台有哪些