Skip to content

Commit 0c68708

Browse files
author
Julien Ponge
committed
Documentation for number type conversions
1 parent bf278bf commit 0c68708

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

doc/predefined-functions.asciidoc

+19-5
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,33 @@ let value = readln()
3131
let pwd = readpwd("type your password:")
3232
----
3333

34+
=== Number type conversions ===
35+
36+
The following functions convert any number of string value to another number type:
37+
`intValue(n)`, `longValue(n)`, `charValue(n)`, `doubleValue(n)` and `floatValue(n)`.
38+
39+
The usual Java type narrowing or widening conventions apply.
40+
41+
[source,golo]
42+
----
43+
let i = intValue("666") # 666 (string to integer)
44+
let j = intValue(1.234) # 1 (double to integer)
45+
let k = intValue(666_L) # 666 (long to integer)
46+
# etc
47+
----
48+
3449
=== Exceptions ===
3550

3651
`raise` can be used to throw a `java.lang.RuntimeException`. It comes in two forms: one with a
3752
message as a string, and one with a message and a cause.
3853

3954
[source,golo]
4055
----
41-
try {
42-
...
56+
try {
57+
...
4358
raise("Somehow something is wrong")
44-
} catch (e) {
45-
...
59+
} catch (e) {
60+
...
4661
raise("Something was wrong, and here is the cause", e)
4762
}
4863
----
@@ -237,4 +252,3 @@ let e = mapEntry("foo", "bar")
237252
# prints "foo => bar"
238253
println(e: getKey() + " => " + e: getValue())
239254
----
240-

0 commit comments

Comments
 (0)