Easy way to change cents style in money text

I have a label (literal, any) that is filled in with currency ($ 5,000). Is there a simple way to style cents, for example, to reduce the font size.

I know that I can break two, but I'm using MVP, and I'm looking for an easy way to pass all these new properties to the control (there are 4+ of these shortcuts).

Open all offers as a new control, not a label, no matter what you get.

+3
source share
5 answers

I would inherit the label class, and then create a newlabel class, StyledMoneyLabel. I have not tested this code, but I hope you get this idea.

class StyledMoneyLabel : Label
{
    double money = 0.0;

    Render(HtmltextWriter)
    {
        HtmlSpan dollars = new HtmlSpan(CSS_CLASS);
        dollars.Text = money.ToString(FORMAT_STRING_FOR_GETTING_DOLLARS.
        ///etc for decimals and so forth
     }
}
+1
source

, Label/Literal. MoneyLabel, Literal, , . Render HTML, .

, , .

, CSS HTML , JavaScript , , , , .NET

+3

, , , - : -

<span class="currency-symbol">£</span>
<span class="major-currency-unit">5000</span>
<span class="decimal-point">.</span>
<span class="minor-currency-unit">00</span>

.

+2

Ideally, you need to format it as follows.

$5000.<span class="Cents">00</span>

How you do this is a little complicated, you can have the "Dollars" and the "Cents" property, and then manipulate the string in format.

+1
source

You can use javascript and let the client do all the heavy lifting ... for example, in jquery (you will need to define the putSpansAroundDollarsAndCents () function)

<div class="currencyToSplit">$5000.00</div>

$(".currencyToSplit").each(function() { putSpansAroundDollarsAndCents($(this)) });
+1
source

Source: https://habr.com/ru/post/1714328/


All Articles