次の方法で共有


Rational.ParseRational(String) Method

Definition

Parses the specified string as a rational value.

[Android.Runtime.Register("parseRational", "(Ljava/lang/String;)Landroid/util/Rational;", "")]
public static Android.Util.Rational? ParseRational (string? string);
[<Android.Runtime.Register("parseRational", "(Ljava/lang/String;)Landroid/util/Rational;", "")>]
static member ParseRational : string -> Android.Util.Rational

Parameters

string
String

the string representation of a rational value.

Returns

the rational value represented by string.

Attributes

Exceptions

if string cannot be parsed as a rational value.

if string was null

Remarks

Parses the specified string as a rational value.

The ASCII characters \u003a (':') and \u002f ('/') are recognized as separators between the numerator and denumerator.

For any Rational r: Rational.parseRational(r.toString()).equals(r). However, the method also handles rational numbers expressed in the following forms:

"num/den" or "num:den" => new Rational(num, den);, where num and den are string integers potentially containing a sign, such as "-10", "+7" or "5".

{@code
            Rational.parseRational("3:+6").equals(new Rational(1, 2)) == true
            Rational.parseRational("-3/-6").equals(new Rational(1, 2)) == true
            Rational.parseRational("4.56") => throws NumberFormatException
            }

Java documentation for android.util.Rational.parseRational(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to