Allows product price decimal point styles to be controlled

Source: Internet
Author: User

Many stores now like to buy custom templates, and there are various design drafts. Some design drafts also want to make the decimal point of the price different from other numbers. This can't be done with pure CSS without adding tags. No way to format the prices as HTML with tagsCode.

.

 1   String Getpricehtml ( String Price)
2 {
3 If ( String . Isnullorempty (price ))
4 {
5 Return String . Empty;
6 }
7
8 VaR Numberformat = thread. currentthread. currentuiculture. numberformat;
9 VaR Decimalseparator = numberformat. currencydecimalseparator;
10 VaR Groupseparator = numberformat. currencygroupseparator;
11
12 If (Price. Contains (decimalseparator ))
13 {
14 VaR Numberregex = New RegEx ( String . Format ( @" [\ {0} \ D] + \ {1} " , Groupseparator, decimalseparator ));
15 Price = numberregex. Replace (price, Delegate (Match)
16 {
17 Return String . Format ( @" <SPAN class = "" Number ""> {0} </span> {1} " , Match. value. substring ( 0 , Match. value. Length- 1 ), Decimalseparator );
18 });
19
20 VaR Decimalregex =New RegEx ( String . Format ( @" \ {0} \ D + $ " , Decimalseparator ));
21 Price = decimalregex. Replace (price, Delegate (Match)
22 {
23 Return String . Format ( @" <SPAN class = "" Decimal-separator ""> {0} </span> <SPAN class = "" decimal "" >{1} </span> " , Decimalseparator, match. value. substring ( 1 ));
24 });
25 } Else
26 {
27 VaR Numberregex = New RegEx ( String . Format (@" [\ {0} \ D] + " , Groupseparator ));
28 Price = numberregex. Replace (price, Delegate (Match)
29 {
30 Return String . Format ( @" <SPAN class = "" Number ""> {0} </span> " , Match. value );
31 });
32 }
33
34 VaR Symbol = numberformat. currencysymbol;
35 Price = Price. Replace (symbol, String . Format ( @" <SPAN class = "" symbol ""> {0} </span> " , Symbol ));
36
37 Return Price;
38 }

Test code:

 
1 VoidMain ()
2{
3Thread. currentthread. currentuiculture =NewCultureinfo ("NL-nl");
4Console. writeline (getpricehtml ("€0. 2.300, 20"));
5}

Result:

<SPAN class = "symbol"> € </span> <SPAN class = "Number"> 2.300 </span> <SPAN class = "Decimal-separator">, </span> <SPAN class = "decimal"> 20 </span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.