Search code examples
c#blazorformattingcurrencytostring

Currency culture formatting nl-NL/BE gives uncorrect format


I'm trying to write a currency in the Dutch format: €1.000,00

meaning:
Euro sign before the amount
Between thousands a dot
Between cents a comma

However when I use CultureInfo "nl-NL" or "nl-BE" it shows: €1,000.00 which is not correct

PrijsDisplay.razor and code behind razor.cs

@using System.Globalization

<span>@Prijs.ToString("C", new CultureInfo("nl-NL"))</span>

@code {
    
}


using Microsoft.AspNetCore.Components;


public partial class PrijsDisplay : ComponentBase
{
    [Parameter]
    public required decimal Prijs { get; set; }
}

Blazorpage.blazor

<PrijsDisplay Prijs="101099" />

Actual Output: €101,099.00

Expected output: €101.099,00

Why does it do this?

I tried various other CultureInfo's, but only the Dutch and Belgians use this format, all other European countries I tried either used . for cents and , for thousands or put the euro sign after the amount


Solution

  • I have tried nl-NL format and it's working fine.

    decimal dutch = 1000M;
    Console.WriteLine (dutch.ToString("C", new CultureInfo("nl-NL")));
    

    Result is: €1.000,00

    Can you retry it, and if it's not working, try to pass parsed currency string as view variable