How to convert a number to string and vice versa in C++

Update for C++11 As of the C++11 standard, string-to-number conversion and vice-versa are built in into the standard library. All the following functions are present in <string> (as per paragraph 21.... Read More

c# - What is the difference between Convert.ToInt32 and (int)?

(int)foo is simply a cast to the Int32 (int in C#) type. This is built into the CLR and requires that foo be a numeric variable (e.g. float, long, etc.) In this sense, it is very similar to a cast in... Read More

c# - Why can I pass 1 as a short, but not the int variable i?

The first two are constant expressions, the last one isn't. The C# specification allows an implicit conversion from int to short for constants, but not for other expressions. This is a reasonable rul... Read More

c# - How to convert from System.Enum to base integer?

If you don't want to cast, Convert.ToInt32() could do the trick. The direct cast (via (int)enumValue) is not possible. Note that this would also be "dangerous" since an enum can have different under... Read More

int - How do I convert from an integer to a string?

Use to_string() (running example here): let x: u32 = 10; let s: String = x.to_string(); println!("{}", s); You're right; to_str() was renamed to to_string() before Rust 1.0 was released for consiste... Read More

casting - How do I convert a string to a number in PHP?

You don't typically need to do this, since PHP will coerce the type for you in most circumstances. For situations where you do want to explicitly convert the type, cast it: $num = "3.14"; $int = (int... Read More

stl - C++ convert vector<int> to vector<double>

Use std::vector's range constructor: std::vector<int> intVec; std::vector<double> doubleVec(intVec.begin(), intVec.end());... Read More

java - Converting char[] to byte[]

Convert without creating String object: import java.nio.CharBuffer; import java.nio.ByteBuffer; import java.util.Arrays; byte[] toBytes(char[] chars) { CharBuffer charBuffer = CharBuffer.wrap(char... Read More

javascript - Convert boolean result into number/integer

Use the unary + operator, which converts its operand into a number. + true; // 1 + false; // 0 Note, of course, that you should still sanitise the data on the server side, because a user can send an... Read More

boolean - Why is "!!" considered bad form in Perl?

I'd call it 'bad form' because it simply isn't necessary. You don't need to boolean convert in Perl. And so at best it's redundant, and at worst it's an obfuscation. While there are some really nice... Read More