Display Number as Currency

I have a .NET C# app with fields formatted as currency, both in the model and the view. model
[DisplayFormat(DataFormatString = "{0:C0}", ApplyFormatInEditMode = true)]
[DisplayFormat(DataFormatString = "{0:C0}", ApplyFormatInEditMode = true)]
view
@item.Payment.ToString("C")
@item.Payment.ToString("C")
It works locally but not on railway, it displays ¤. It works if I use [email protected]("#,###,###.##") in the view but then it will display .2 instead of .20, and I have to put in the $ character at the beginning. Any help solving this would be much appreciated. here is the link to the app https://mortgagecalculator-asp-net.up.railway.app/Home/App
Solution:
Got it 🙂 in the view ``` @Model.Payment.ToString("C", CultureInfo.CreateSpecificCulture("en-US"))...
Jump to solution
14 Replies
Percy
Percy13mo ago
Project ID: N/A
David Bellerose
David Bellerose13mo ago
N/A
Adam
Adam13mo ago
Looks like your dollar sign isn’t playing nicely with your number format. is it possible to add a $ in the value format like {$0:C0}? I’m thinking like excel otherwise, take the string from the value format and append on the dollar sign before printing. Don’t run the dollar sign through the value format
David Bellerose
David Bellerose13mo ago
no {$0:C0} didn't work. If I understand you correctly regarding the value format I tried this.. [email protected]("C") but it displays this and it still display a .2 without the extra 0
Brody
Brody13mo ago
displays like that where exactly though?
David Bellerose
David Bellerose13mo ago
displays like this on the page
No description
Brody
Brody13mo ago
are you sure you are formatting your text with utf-8, that's a common problem I've seen
David Bellerose
David Bellerose13mo ago
no not sure. I'm googling it now. Do you know how to do that in a razor view?
Brody
Brody13mo ago
nope, never touched .net definitely something to Google though, maybe even setting utf-8 on the content headers would be enough, that's actually worked for me before
David Bellerose
David Bellerose13mo ago
put this in the razor layout page head tag but it didn't work
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Brody
Brody13mo ago
I mean on the actual http headers but it was only a thought
David Bellerose
David Bellerose13mo ago
here is the ascii info for this character
No description
Solution
David Bellerose
David Bellerose13mo ago
Got it 🙂 in the view
@Model.Payment.ToString("C", CultureInfo.CreateSpecificCulture("en-US"))
@Model.Payment.ToString("C", CultureInfo.CreateSpecificCulture("en-US"))
and the using statement at the top of the view
@using System.Globalization;
@using System.Globalization;
Thanks guys for the help 👍
Brody
Brody13mo ago
awesome!
Want results from more Discord servers?
Add your server