0

I found how to change the locale format in Java, but I want to use it in C#.

This is the (Java) line of code

String.format(Locale.US, "%f", floatValue)
Tassisto
  • 9,877
  • 28
  • 100
  • 157
  • 2
    See: [`String.Format` which takes a `IFormatProvider` (implemented by 'CultureInfo`)](http://msdn.microsoft.com/en-us/library/1ksz8yb7%28v=vs.110%29.aspx) – Jamiec Feb 24 '14 at 12:55
  • My question could be duplicate but it has a different and good answer. – Tassisto Feb 26 '14 at 12:58

3 Answers3

1

For Culture you can Use

CultureInfo en = new CultureInfo("en-US");

and for Formatting Float with Culture you can use

string.Format(new System.Globalization.CultureInfo("en-Us"), "{N2}", floatValue)
Aftab Ahmed
  • 1,727
  • 11
  • 15
1

C# equivalent is (simple to string conversion)

 String result = floatValue.ToString(new CultureInfo("en-US"));

Or (formatting)

 String result = String.Format(new CultureInfo("en-US"), "{0}", floatValue);
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
0

By default in .Net if you use CultureInfo.InvariantCulture it is associated with the English language en-US or you can explicitly set CUltureInfo

float value = 16325.62015;   
// Display value using the invariant culture.
Console.WriteLine(  value.ToString(CultureInfo.InvariantCulture));
// Display value using the en-US culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-US")));
BRAHIM Kamel
  • 13,492
  • 1
  • 36
  • 47