converting numbers to strings and back
dominik
aha at aha.com
Fri Oct 5 20:56:44 PDT 2007
I was trying, for fun and learning, to do some PHP style trash programming.
Basically, I wanted to convert float to string, and string back to float. I
did make it work, but not as documentation said I should. Look at the
commented out line in example I made.
I'm trying to learn D (I'm coming from HEAVY C and PHP background), so I
occasionally post questions which might seem retarded. I'm sorry, and thank
you for your patience and help :)
Documentation for D is still pretty sparse on the interwebtubes - luckly
this newsgroup is pretty active and helpfull. Is there a place where D
documentation is centralized? Like php.net for PHP for example - which I
find the most usefull documentation formats for any language (including
standard library) I've been working with. I have found several places on
net, but none seem to be active and/or full of information. I'd like to
contribute as I'm learning, so others can find more information easily.
--------------------------------------------
import std.stdio;
import std.string;
import std.conv;
void main(char[][] args) {
float fFloat = 214.4;
float fBack = 0;
char[] cTest = std.string.toString(fFloat);
writefln(cTest);
// fBack = to!(float)(cTest); // this does not work! Why?
fBack = toFloat(cTest);
// This does work, but docs say it will be deprecated
// because to!(T) supercedes it.
writefln(fBack);
}
--------------------------------------------
More information about the Digitalmars-d-learn
mailing list