using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class strChange : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //设置货币小数部分的数值 showValue.InnerHtml = GetNumberFormat("134.12554", 3); //格式化数据为货币格式 showValue.InnerHtml += "<br />" + GetFormatNumber("134.12554"); //进制转换 showValue.InnerHtml += "<br />十转二:"; showValue.InnerHtml += Convert.ToString(10, 2); showValue.InnerHtml += "<br />十转八:"; showValue.InnerHtml += Convert.ToString(10, 8); showValue.InnerHtml += "<br />十转十六:"; showValue.InnerHtml += Convert.ToString(10, 16); showValue.InnerHtml += "<br />二转八:"; showValue.InnerHtml += Convert.ToString(Convert.ToInt64("1010", 2), 8); showValue.InnerHtml += "<br />二转十:"; showValue.InnerHtml += Convert.ToInt64("1010", 2).ToString(); showValue.InnerHtml += "<br />二转十六:"; showValue.InnerHtml += Convert.ToString(Convert.ToInt64("1010", 2), 16); showValue.InnerHtml += "<br />八转二:"; showValue.InnerHtml += Convert.ToString(Convert.ToInt64("12", 8), 2); showValue.InnerHtml += "<br />八转十:"; showValue.InnerHtml += Convert.ToInt64("12", 8).ToString(); showValue.InnerHtml += "<br />八转十六:"; showValue.InnerHtml += Convert.ToString(Convert.ToInt64("12", 8), 16); showValue.InnerHtml += "<br />十六转二:"; showValue.InnerHtml += Convert.ToString(Convert.ToInt64("a", 16), 2); showValue.InnerHtml += "<br />十六转十:"; showValue.InnerHtml += Convert.ToString(Convert.ToInt64("a", 16), 8); showValue.InnerHtml += Convert.ToUInt64("a", 16).ToString(); //确定弹窗 Button1.Attributes["OnClick"] = "return confirm(‘你确定么?‘)"; } private string GetNumberFormat(string str,int deci) { double value; string returnVal = ""; if (double.TryParse(str, out value)) { NumberFormatInfo NFI = new CultureInfo("zh-CN", false).NumberFormat; NFI.CurrencyDecimalDigits = deci; returnVal = value.ToString("C", NFI); } else { returnVal = "数值不正确~!"; } return returnVal; } private string GetFormatNumber(string str) { double value; string returnVal = ""; if (double.TryParse(str, out value)) { NumberFormatInfo NFI = new CultureInfo("zh-CN", false).NumberFormat; NFI.CurrencyGroupSeparator = ","; //设置货币中对小数点左边的数字分组的字符串 returnVal = value.ToString("C", NFI); } else { returnVal = "数值不正确~!"; } return returnVal; } protected void Button1_Click(object sender, EventArgs e) { showValue.InnerHtml += "<br /> 您点击了确定!"; } }
交流群:225443677
时间: 2024-10-18 04:33:37