Hi, how can I in a floatvariable a String "installation when" the float to 2 digits after the decimal point limit?
One can for example, the first floating point number two decimal places to round out the string and then write. Here's an example code for rounding: Code: #include <iostream> using namespace std; int main() { float zahl; cin >> zahl; zahl = int( 100*zahl + 0.5 ) / 100.0; //runden auf 2 Nachkommastellen cout << zahl; return 0; }
Thank you forgot to say that I Basisstation a CString. The rounds went well with that, but how do I get it out that if I then only with two digits after the comma in the string will have the number? So string.Format (" % f ", num);
1st looking times in the FAQ, then you knew more ... second the resolution of the should be at best int ... Code: int = float * 100; float = int, float / = 100; CString:: format ("% f", float);
Code: CString strFloat; / / Here is the float-variable inside strFloat.SetAt ((strFloat.Find (' .') +2),' \ 0 '); The idea: I am looking for the point ('.'), So put the comma, and put two characters followed by a '\ 0', which ends the string
Thanks creative, but that did not mean I have as far as ego already at Erhard understood. After your method is yes, then the string as: 12.560000 , it is only 12:56 in the string are. and the method of techme I can not even use, because in String 3 floats each will stand with 2nachkommastellen.
but then take only three strings, each with a float inside the pack-var and then together an easy-to-string
Hello, try the following times: Code: float fValue = 0.047645645; CString strAusgabe; strAusgabe.Format (" % .2 f ", fValue); the .2 you lay by the precision fixed. In the fall she is 2 decimal places. The float is automatically rounded, ie strAusgabe contains the string "0.05"
Uff! Do not something like! You have very bad problems later if you believe in what the string anhengen still want! Code: CString strWithNULL = " Hello "; strWithNULL.Replace (" ! "," \ 0 "); strWithNULL + = " hello "; MessageBox (strWithNULL); The MessageBox is now Hello and nciht, as perhaps expected Hello, hello ...