An inverse operation of string.toDouble()?

Hello,

I'm quite new to Arduino and C-programming and right now I'm trying to make a scientific calculator. In order to accomplish the brackets-function I must convert a double into a string, sort of the opposite of what the string.toDouble() function is doing.

I.e. something like this:

String myString = "";
double myNumber = 176.293402;
myString = myNumber.toString();  //Imaginary function turning myString into "176.293402".

It would need fairly much code to do it "manually", so if there's a simple function someone could suggest I would be grateful.

Where do you want to put that string? Most "printable" outputs (like Serial and displays) have the Stream clas implemented which can accept a double.

PS strings don't have a method called toDouble(). Strings (with a capital) do but are an easy place to make memory corruption.

I’m using the String with capital S, since I find the syntax a bit easier. I need to use the String because it’s going into another, longer, String using the .charAt() (or similar) function.

for(int i=0; i<myString.length(); i++){
  otherString.setCharAt(i+5, myString.charAt(i));
}

Thanks for the quick answer :smiley:

HerrGustafsson:
I'm using the String with capital S, since I find the syntax a bit easier. I need to use the String because it's going into another, longer, String using the .charAt() (or similar) function.

There are a lot of good reasons why you should not use the String class. Saying the syntax is easier is an excuse, not a reason. If you're going to work in the Arduino IDE, you need to learn C. There is nothing done in the String class that you can't do in "straight" C. There are numerous C string processing functions, which are based on char arrays, that you can use. You can find a list here. There are many examples of using each, just do a search on whatever specific function you need.