< Day Day Up > |
TechniqueDisplaying currency information is similar to displaying culturally aware numerical data. Because currency itself is a number, you can use the same technique of passing a NumberFormatInfo object into a method that utilizes an IFormatProvider parameter. To change a number so it is formatted as currency, use the currency format specifier within the method: private void numericUpDown1_ValueChanged(object sender, System.EventArgs e) { // demonstrates formatting a value using correct culture number format NumberFormatInfo currentNFI = new CultureInfo(cbLanguage.SelectedItem.ToString(),false).NumberFormat; // C is the currency format specifier lblCurrency.Text = numericUpDown1.Value.ToString( "C", currentNFI ); } CommentsCurrency itself is simply a number, and which is why there is no need for a CurrencyFormatInfo object. The NumberFormatInfo class contains several currency- related properties that it uses within its GetFormat method to correctly format a number as a currency value. Also, you only need to specify a NumberFormatInfo object if you want to display a currency value in a culture different from that of the user 's current culture. One thing you should know is that the formatting does not take current exchange rates into consideration. |
< Day Day Up > |