This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
Idiom #55 Convert integer to string
Create the string representation s (in radix 10) of the integer value i.

- Ada
- C
- Clojure
- C++
- C#
- D
- Dart
- Elixir
- Elixir
- Elixir
- Erlang
- Fortran
- Go
- Go
- Go
- Groovy
- Haskell
- JS
- JS
- Java
- Java
- Java
- Java
- Java
- Java
- Kotlin
- Lisp
- Lua
- Obj-C
- PHP
- PHP
- PHP
- PHP
- Pascal
- Pascal
- Perl
- Perl
- Python
- Ruby
- Rust
- Rust
- Scala
- Scheme
- Smalltalk
- VB
def s = "$i".toString()
While any of the Java examples works in Groovy, too, you can also use string interpolation like shown here.
String interpolation ("$i") gives you a GString, which in many places can be used as a string because it is a CharSequence. Here, for clarity, the GString is converted to a String using the toString() method.
String interpolation ("$i") gives you a GString, which in many places can be used as a string because it is a CharSequence. Here, for clarity, the GString is converted to a String using the toString() method.
my $s = "" . $i;
Perl automatically converts numbers to strings, and strings to numbers, whenever required. The concatenation with the empty string is superfluous, it only indicates programmer intent.