Search code examples
c#blazorblazor-client-side

Blazor: Can I add thousand separator when using @variable to print values on the page?


For example, in a code like this,

<p>Size = @Size</p>

@code {
long Size = 1234567890;
}

can I print the value like "1,234,567,890"?


Solution

  • Try this

    <button @onclick="Demo">Click</button>
    <span>@stringSize</span>
    
    @code {
    
        long  size = 1234567890;
        string stringSize = "";
    
        private void Demo()
        { 
            stringSize = (size).ToString("#,##0.00");
        }
    
    }