From 7bb682651f1dca4bc4a7a1b8ff67e6c9e288dc54 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 16 Jan 2022 02:11:30 +0100 Subject: [PATCH] Clarify to_float() and to_int() methods --- doc/classes/String.xml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/doc/classes/String.xml b/doc/classes/String.xml index d86c577e5e7..c8e835f0f1d 100644 --- a/doc/classes/String.xml +++ b/doc/classes/String.xml @@ -684,13 +684,24 @@ - 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] - 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]