Boom
Boom

Reputation: 29

Display data from decimal to integer

In database show column for "value" is 0.06 with datatype decimal(18,2).

How can i display in textbox value with value 6 Not 0.06?

I try change format to {0} but not successful. If used convert, How can i convert it?

<input type="text" runat="server" title="value" id="value" name="value"/>

protected string r_value = string.Empty;
protected void Page_Load(object sender, EventArgs e)
    {

        if (String.Format("{0}",Request.Params["value"]) != null) r_value =  String.Format("{0}",Request.Params["value"]);


    if (!IsPostBack)
        {          

            list_Detail();

        }
    }

 private void list_Detail()
    {
        try
        {
            BizeValue biz = new BizeValue();
            DataSet ds = biz.SPValue(r_ven);

            if (ds.Tables[0].Rows.Count > 0)
            { 
                DataRow row = ds.Tables[0].Rows[0];

                value.Value = String.Format("{0}", row["value"]) != null ? String.Format("{0}", row["value"]) : "";       
            }

        }
        catch (Exception ex)
        {
            base.scriptAlert("Raised Exception");
        }

    }

Upvotes: 0

Views: 151

Answers (3)

Monkawee Maneewalaya
Monkawee Maneewalaya

Reputation: 150

I recommend to declare variables.One is for convert value from database to numeric and multiply by 100 and convert One to string and keep it in Two or display. Example:

decimal a;
string b;

a = decimal.Parse(<Value>)
a = a*100
b = a.ToString()

Upvotes: 0

user3777811
user3777811

Reputation:

If you want to cast a string to Integer means you can use Int.TryParse(). But for 0.06 it will return the value as 0.

Upvotes: 0

Eric J.
Eric J.

Reputation: 150238

How can i display in textbox value with value 6 Not 0.06?

If you try to cast 0.06 to an integer, you get 0.

It sounds like you are trying to convert a decimal value in the range 0.0 to 1.0 into a percentage in the range 0 to 100. Just multiply your decimal value by 100 before casting to an integer.

Upvotes: 2

Related Questions