Skip to content

Instantly share code, notes, and snippets.

@toby55kij
Created October 11, 2010 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toby55kij/619996 to your computer and use it in GitHub Desktop.
Save toby55kij/619996 to your computer and use it in GitHub Desktop.
// g100pon #53 いろいろな型変換(toメソッド、キャスト、as)
// toメソッド
// 文字から数値へ
def a = '123'.toInteger()
assert a.class == Integer
def b = '123.45'.toBigDecimal()
assert b.class == BigDecimal
// 数値から文字へ
def c = (10*2).toString()
assert c.class == String
// キャスト
def d = (int)(12.5 * 2)
assert d.class == Integer
// as
def e = 123 as String
assert e.class == String
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment