user entering decimal value but view purpose converting to $value
ex:9.86 to $9.86
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Sep 11, 2013, 8:23 AM
decimal dec = 12.34m;
string dollar = "$" + dec.ToString("F"); // output to 2 dp
ThrishPosted Sep 11, 2013, 11:17 AM
{
decimal dollarAmount = decimal.Parse(textBox2.Text);
string text = dollarAmount.ToString("C");
textBox2.Text = text;
}
Sanjeeb LenkaPosted Sep 11, 2013, 8:19 AM
use this name space:
using System.Globalization;
in aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
in.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Decimal currency = Convert.ToDecimal(TextBox1.Text, new CultureInfo("en-US"));
string money = currency.ToString("C");
if (currency % 1 == 0)
{
money = money.Substring(0, money.Length - 3);
}
Label1.Text = money.ToString();
}
}