In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces how to add currency symbols and uppercase conversion to the Web page. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
The display of data on Web pages often involves a variety of data formatting, among which it is common to add currency symbols and uppercase conversions.
1. Implementation method of code development version
Define the data conversion function, which is called by the page.
1)。 Add a currency symbol function:
a. Get the value to be processed to determine whether it is a valid value
b. Converts a numeric value to a string type, positioning to add a currency symbol before the first number.
Core code:
Function currency (money) {let val = money; if (val) {val ='$'+ val;return val;}}
Note: currency symbol conversion often requires synchronous thousand-digit format processing, which requires the code to process the content before and after the decimal point step by step, such as: var re=/ (? = (?! (\ b)) (\ d {3}) + $) / g; money1= money1.replace (re, ",")
2). The case conversion function is an example:
a. Define the maximum amount handled
b. Judge the range of the amount (> 0, = 0, 0) {/ / get the integer part conversion var zeroCount = 0; var IntLen = IntegerNum.length; for (var I = 0; I
< IntLen; i++) { var n = IntegerNum.substr(i, 1); var p = IntLen - i - 1; var q = p / 4; var m = p % 4; if (n == "0") { zeroCount++; } else { if (zeroCount >0) {ChineseStr + = cnNums\ [0\];} zeroCount = 0; / / zeroing ChineseStr + = cnNums\ [parseInt (n)\] + cnIntRadice\ [m\];} if (m = = 0 & & zeroCount
< 4) { ChineseStr += cnIntUnits\[q\]; } } ChineseStr += cnIntLast; //整型部分处理完毕 } if (DecimalNum != '') { //小数部分 var decLen = DecimalNum.length; for (var i = 0; i < decLen; i++) { var n = DecimalNum.substr(i, 1); if (n != '0') { ChineseStr += cnNums\[Number(n)\] + cnDecUnits\[i\]; } } } 2. 更便捷多用的方法 使用内置数据显示转换功能的报表工具,通过简单的设置达到数据转换的效果。 1) 添加货币符号配置2) numerical capitalization conversion
Note: in addition to the above conversion can be easily and quickly achieved by using the tool, you can also make more display settings, such as: numerical value to Chinese, date format and so on.
Compared with the above two situations, although the former code can achieve the requirements of conversion, it requires developers to have clear logical thinking and clear thinking, otherwise the conversion is likely to be incorrect because the consideration is not comprehensive enough. and often a page needs to do a lot of data formatting processing, each written in this way is very troublesome, and subsequent maintenance is also difficult.
On the Web page how to add currency symbols and capitalization conversion to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.