Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if i assign large float number on the other page im trying to assigning to other float which is throwing me a error because of scientific notation in that float value. how to get a float value without any scientific notation


C#
if (Request.QueryString["Amount"] != null)
           {
               float Amount = float.Parse(Request.QueryString["Amount"].ToString());
               ((TextBox)fv_brokerpayment.FindControl("PaidAmountTextBox")).Text = Amount.ToString();

               int PaymentID = crudobj.GenerateID("Payment_tbl");
               ((TextBox)fv_brokerpayment.FindControl("PaymentIdTextBox")).Text = PaymentID.ToString();
               ((TextBox)fv_brokerpayment.FindControl("Ref_BrokerIdTextBox")).Text = Session["BrokerRefID"].ToString();
               ((TextBox)fv_brokerpayment.FindControl("PaidDateTextBox")).Text = DateTime.Now.ToString();
           }



im getting error in this line

Quote:
float Amount = float.Parse(Request.QueryString["Amount"].ToString());


//eg:
Quote:
{Amount=1.111111E+07}
Posted

Hi,

Can you try it this way:
C#
float Amount = float.Parse(Request.QueryString["Amount"].ToString(), System.Globalization.NumberStyles.Float);


But in case, the value is too large, like
Use it this way:
C#
double Amount = double.Parse("1.111111E+07", System.Globalization.NumberStyles.Float);


Regards,
Praneet
 
Share this answer
 
v2
I'd be tempted to replace this

float Amount = float.Parse(Request.QueryString["Amount"].ToString());


with

float Amount = float.Parse(Request.QueryString["Amount"].ToString(), System.Globalization.NumberStyles.Float);


to start with - but be aware, that's likely to fail if the current culture's decimal point separator isn't '.' - so you might need to use this form below instead

float Amount = float.Parse(Request.QueryString["Amount"].ToString(),System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture);


[edit] btw, giving us the error message might also have been useful [/edit]
 
Share this answer
 
v2
Comments
Member 10491373 30-Oct-14 6:40am    
since if i use this code i get an error as "Input string was not in a correct format."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900