PDA

View Full Version : فرمت داده(فوری)



golagha_program
سه شنبه 21 آذر 1385, 10:05 صبح
سلام
یک سوال ساده دارم که بد جوری مچلم کرده.
در بانک اطلاعاتی یک فیلد float دارم داده هاش رو توی تکست باکس نمایش میدم کلی رقم اعشار داره.1-می خوام 2 رقم اعشار داشته باشم.2-فرمت نمایش رو خودم تعیین کنم مثلا"
1/234 یا1.234

golagha_program
چهارشنبه 22 آذر 1385, 09:23 صبح
سلام
کسی نیست جواب ما رو بده

ghafoori
چهارشنبه 22 آذر 1385, 19:02 عصر
شما می توانید از تابع فرمت string یا single یا decimal استفاده کنید مثل کد زیر


// Example for the Decimal.ToString( ) methods.
using System;
using System.Globalization;
using Microsoft.VisualBasic;

class DecimalToStringDemo
{
static void Main()
{
decimal nineBillPlus = 9876543210.9876543210M;

Console.WriteLine("This example of\n" +
" Decimal.ToString( ), \n" +
" Decimal.ToString( String ),\n" +
" Decimal.ToString( IFormatProvider ), and \n" +
" Decimal.ToString( String, IFormatProvider )\n" +
"generates the following output when run in the " +
"[{0}] culture.\nDecimal numbers are formatted " +
"with various combinations \nof format strings " +
"and IFormatProvider.",
CultureInfo.CurrentCulture.Name);

// Format the number without and with format strings.
Console.WriteLine("\nIFormatProvider is not " +
"used; the default culture is [{0}]:",
CultureInfo.CurrentCulture.Name);
Console.WriteLine(" {0,-30}{1}", "No format string:",
nineBillPlus.ToString());
Console.WriteLine(" {0,-30}{1}", "'N' format string:",
nineBillPlus.ToString("N"));
Console.WriteLine(" {0,-30}{1}", "'N5' format string:",
nineBillPlus.ToString("N5"));

// Create a CultureInfo object for another culture. Use
// [Dutch - The Netherlands] unless the current culture
// is Dutch language. In that case use [English - U.S.].
string cultureName =
CultureInfo.CurrentCulture.Name.Substring(0, 2) ==
"nl" ? "en-US" : "nl-NL";
CultureInfo culture = new CultureInfo(cultureName);

// Use the CultureInfo object for an IFormatProvider.
Console.WriteLine("\nA CultureInfo object " +
"for [{0}] is used for the IFormatProvider: ",
cultureName);
Console.WriteLine(" {0,-30}{1}", "No format string:",
nineBillPlus.ToString(culture));
Console.WriteLine(" {0,-30}{1}", "'N5' format string:",
nineBillPlus.ToString("N5", culture));

// Get the NumberFormatInfo object from CultureInfo, and
// then change the digit group size to 4 and the digit
// separator to '_'.
NumberFormatInfo numInfo = culture.NumberFormat;
numInfo.NumberGroupSizes = new int[] { 4 };
numInfo.NumberGroupSeparator = "_";

// Use a NumberFormatInfo object for IFormatProvider.
Console.WriteLine(
"\nA NumberFormatInfo object with digit group " +
"size = 4 and \ndigit separator " +
"= '_' is used for the IFormatProvider:");
Console.WriteLine(" {0,-30}{1}", "'N5' format string:",
nineBillPlus.ToString("N5", culture));
Console.ReadLine();
}
}داخل msdn حالات مختلف دستور فرمت وجود دارد