Skip to content

Commit

Permalink
Clarify to_float() and to_int() methods
Browse files Browse the repository at this point in the history
(cherry picked from commit 7bb6826)
  • Loading branch information
KoBeWi authored and akien-mga committed Jan 19, 2022
1 parent 7eb8339 commit ccb52db
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions doc/classes/String.xml
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,24 @@
<method name="to_float">
<return type="float" />
<description>
Converts a string containing a decimal number into a [code]float[/code].
Converts a string containing a decimal number into a [code]float[/code]. The method will stop on the first non-number character except the first [code].[/code] (decimal point), and [code]e[/code] which is used for exponential.
[codeblock]
print("12.3".to_float()) # 12.3
print("1.2.3".to_float()) # 1.2
print("12ab3".to_float()) # 12
print("1e3".to_float()) # 1000
[/codeblock]
</description>
</method>
<method name="to_int">
<return type="int" />
<description>
Converts a string containing an integer number into an [code]int[/code].
Converts a string containing an integer number into an [code]int[/code]. The method will remove any non-number character and stop if it encounters a [code].[/code].
[codeblock]
print("123".to_int()) # 123
print("a1b2c3".to_int()) # 123
print("1.2.3".to_int()) # 1
[/codeblock]
</description>
</method>
<method name="to_lower">
Expand Down

0 comments on commit ccb52db

Please sign in to comment.