Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert double to string

i have three double variable a ,b and c

a = 0.000006 
b = 6 
c = a/b;

so C should be 0.000001

i want to show this value in text box so i wrote

textbox.text = c.tostring();

but it's give result as "1E-06"..

Can anybody help me out how can i put correct value in textbox ?

Thanks

like image 905
Kartik Avatar asked Feb 10 '09 20:02

Kartik


People also ask

How do I convert a double array to a String?

You can convert a double array to a string using the toString() method. To convert a double array to a string array, convert each element of it to string and populate the String array with them.

How do I convert a double to a String in Salesforce?

How do I convert a Double to String? From the apex documentation: Double myDouble = 12.34; String myString = String. valueOf(myDouble);

Can you add a double to a String?

The “+” operator with a String acts as a concatenation operator. Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object. In-fact adding a double value to String is the easiest way to convert a double value to Strings.


2 Answers

a = 0.000006;
b = 6;
c = a/b;

textbox.Text = c.ToString("0.000000");

As you requested:

textbox.Text = c.ToString("0.######");

This will only display out to the 6th decimal place if there are 6 decimals to display.

like image 156
Adam Davis Avatar answered Oct 19 '22 20:10

Adam Davis


Try c.ToString("F6");

(For a full explanation of numeric formatting, see MSDN)

like image 34
Jim Arnold Avatar answered Oct 19 '22 20:10

Jim Arnold