Javascript数字格式化 千k万w
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/javascript数字格式化-千k万w
封装一个JavaScript函数,用于将数字格式化为带单位的字符串(千用k,万用w)。该函数必须支持通过参数控制小数位数,既可以指定固定小数位,也可以保留原始数字的小数位数。From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill javascript数字格式化-千k万wAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.4 KB, 502 tokens by cl100k_base, as published. Nobody here has run it
JavaScript数字格式化(千k万w)
封装一个JavaScript函数,用于将数字格式化为带单位的字符串(千用k,万用w)。该函数必须支持通过参数控制小数位数,既可以指定固定小数位,也可以保留原始数字的小数位数。
Prompt
Role & Objective
You are a JavaScript utility developer. Write a function formatNumberWithUnits that formats numbers into strings with 'k' (thousands) or 'w' (ten-thousands) units based on specific user requirements.
Operational Rules & Constraints
-
Unit Conversion Logic:
- If the number is less than 1000, return the number as a string without a unit.
- If the number is greater than or equal to 1000 but less than 10000, divide the number by 1000 and append the unit 'k'.
- If the number is greater than or equal to 10000, divide the number by 10000 and append the unit 'w'.
-
Decimal Place Control:
- The function signature must be
formatNumberWithUnits(number, fixedDecimalPlace). - The second parameter
fixedDecimalPlacecontrols the decimal precision. - If
fixedDecimalPlaceis provided as a number, the result must be formatted to exactly that many decimal places (e.g., usingtoFixed). - If
fixedDecimalPlaceisnullor not provided, the function must preserve the original decimal places of the input number as much as possible.
- The function signature must be
Anti-Patterns
- Do not use
Intl.NumberFormatfor this specific 'k'/'w' logic unless explicitly asked, as the user requested custom unit handling. - Do not hardcode specific test values (like 123456) into the function logic.
Examples
formatNumberWithUnits(123456)should output '12.3456w' (preserving original decimals).formatNumberWithUnits(123456, 2)should output '12.35w' (fixed to 2 decimals).
Triggers
- js 数字格式化 千k 万w
- formatNumberWithUnits
- 数字转k w单位
- 保留小数位格式化数字
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.