logo
down
shadow

Why won't C# decimal ToString request culture AND currency?


Why won't C# decimal ToString request culture AND currency?

By : krishna
Date : November 22 2020, 04:01 AM
it helps some times I am not sure if I am understanding you question, but for example if you want a double to be expressed as a currency for different countries then you need to provide the different CultureInfo for it.
code :
double foo = 3;
string fooGerman = foo.ToString("C", CultureInfo.GetCultureInfo("de-DE"));
string fooEnglish = foo.ToString("C", CultureInfo.GetCultureInfo("en-GB"));
Console.WriteLine(fooGerman);
Console.WriteLine(fooEnglish);

OUTPUT
3,00 €
£3.00


Share : facebook icon twitter icon
Custom Currency symbol and decimal places using decimal.ToString("C") and CultureInfo

Custom Currency symbol and decimal places using decimal.ToString("C") and CultureInfo


By : der_franzose
Date : March 29 2020, 07:55 AM
I hope this helps . To get a format like RM 11,123,456.00 you also need to set the following properties
code :
CurrentCulture modified = new CultureInfo(Thread.CurrentThread.CurrentCulture.Name);
Thread.CurrentThread.CurrentCulture = modified;
var numberFormat = modified.NumberFormat;
numberFormat.CurrencySymbol = "RM";
numberFormat.CurrencyDecimalDigits = 2;
numberFormat.CurrencyDecimalSeparator = ".";
numberFormat.CurrencyGroupSeparator = ",";
C# culture info/setting up a specific tostring for currency

C# culture info/setting up a specific tostring for currency


By : Sathyananthan Natara
Date : March 29 2020, 07:55 AM
To fix this issue You should be looking into the overload ToString("#,###.00##", myFormatProvider)
So you need a custom IFormatprovider.
Format any currency and amount for current culture (not culture of the currency)

Format any currency and amount for current culture (not culture of the currency)


By : Stuckinadessert
Date : March 29 2020, 07:55 AM
it should still fix some issue To set the current symbol to the desired one (£, $, € or whatever else) while still using the other attributes of the current culture, you can just clone your current NumberFormatInfo and replace the currency symbol:
code :
var cultureInfo = Thread.CurrentThread.CurrentCulture;
var numberFormatInfo = (NumberFormatInfo)cultureInfo.NumberFormat.Clone();
numberFormatInfo.CurrencySymbol = "€"; // Replace with "$" or "£" or whatever you need

var price = 12.3m;
var formattedPrice = price.ToString("C", numberFormatInfo); // Output: "€ 12.30" if the CurrentCulture is "en-US", "12,30 €" if the CurrentCulture is "fr-FR".
Get the culture Info of already formatted decimal or integer to currency

Get the culture Info of already formatted decimal or integer to currency


By : dingyi
Date : March 29 2020, 07:55 AM
will help you The culture isn't part of the string representation of the number. That information is lost.
You can make some guesses, but in the end, it's best to simply include the culture information as well - either as part of your data directly, or in configuration. The main problem is that there are many overlaps between different cultures that may mean you'd mis-identify a particular value and interpret it entirely wrong. And there's no reason why a en-US culture couldn't use € in a number just because the "native currency" is $.
ASP.NET Eval ToString Format Currency Culture Specifying

ASP.NET Eval ToString Format Currency Culture Specifying


By : Andrei S
Date : March 29 2020, 07:55 AM
it should still fix some issue , Try this one
code :
<%# String.Format( new System.Globalization.CultureInfo("tr-TR"), "{0:C}", Eval("Fiyat") %>
Related Posts Related Posts :
  • Replace "\\" with "\" in a path
  • CSS Not formatting inside repeater
  • CheckedListBox filter with a TextBox
  • How to not evaluate the third part of a ternary operator unless necessary
  • How to avoid going into cache block in c# and return to loop iteration?
  • How do I add just one element to an array when I call a method c#
  • Image.RotateFlip doesn't seem to rotate the Bitmap
  • swagger add document and operation for a generic controller
  • Avoid a random selection of the same point to imitate "human-like" behavior
  • Howto use PostgreSQL table names without double quotes in C# and Npgsql
  • .NET Core Entity Framework InvalidOperationException
  • Database Context save if valid
  • How do I flatten an array of arrays?
  • Serialize Property as Xml Attribute in new Element
  • How to make a flash-animation with a row of pictureboxes?
  • Add ClientId to the "Authorized API Clients"
  • Sending data between 2 forms
  • How do you get POSTed value from dynamically populated dropdownlist without the use of UpdatePanel?
  • C# Inconsistent accessibility: return type is less accessible than method
  • MVC Razor how to get option value from form and set viewmodel property to selected value
  • Automapper error after updating a record with POCO classes, Unity and EF6
  • Xamarin Forms Change NavBar background image on Specific pages
  • No service while customize a new User Context Identity
  • How to recognize element in which item in the gridview
  • Loading DataGridView only once based on listbox item selected
  • WCF Service not hitting from postman over https
  • Export telerik RadGrid to PDF
  • Using constant string in all include pages
  • Write Roslyn analyzer by Rider
  • What is the difference between a dSYM folder and an mSYM folder?
  • replace inheritance with generic extension method
  • C# XAML binding
  • Span<T> and streams in .NET framework
  • Using phyton.exe in .net c# controller:
  • How to get distinct values from set of rows matching condition
  • MySqlParameter type conflict when using Entity Framework with Pomelo
  • Why there is black color shed on the upper side and left side on textbox border in ASP.Net
  • Autofac resolving named service incorrectly
  • Cumulative sum of array items
  • Bot connector returns Forbidden (403) with Microsoft.Bot.Connector.ErrorResponseException
  • What is the right way to show only group by column in datatable
  • C# Trying to get a list of questions from one class into my Main() class loop
  • In database AutoIncrease column. What if value reached maximum value
  • How to access controls of dynamically added user controls in a panel in C#?
  • Dynamic DataTable Group by and Aggregate functions
  • Binding selected ListBox Image somewhere else in MainWindow
  • Apply Ninject to work with "child viewmodels" in my C# WPF application
  • Create System.Net.WebProxy from string including credentials
  • error in implementing Ignite.net with persistence
  • WPF Button click not properly comparing variable to array value
  • Create custom iterable Dictionary with one generic type
  • How do I use ExecuteScalar with a stored Procedure?
  • HttpPostedFileBase always returns null when posting it with Model but working perfact without model
  • WIndows 10 MIDL.exe
  • Different versions of ODAC causing error in C# application (local Vs Server)
  • Is it necessary to add [XamlCompilation(XamlCompilationOptions.Compile)] above every class in a Xamarin Forms App?
  • Creating Custom Picturebox with Draggable and Resizable Selection Window
  • Unable to connect to MongoDb (using authentication) using mongocsharpdriver 2.7.0
  • SSIS Script Task: Select from datatable1 into datatable2
  • reversing an array using methods and MessageBox.show
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org