Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

System.Globalization.NumberStyles: practical reference

System.Globalization.NumberStyles: practical reference: NumberStyles is a flag set that specifies which syntactic components a numeric parser may accept.

Version: .NET API; verified on .NET 10.0.14

Syntax

System.Globalization.NumberStyles /* select a documented member or constructor */

NumberStyles is a flag set that specifies which syntactic components a numeric parser may accept.

Combine only the needed flags with the correct CultureInfo in Parse or TryParse.

Overly broad flags can accept an unintended currency sign, separator, exponent, or whitespace.

Not every flag combination is valid for every numeric type, and an invalid combination can throw ArgumentException.

The complete program actually uses System.Globalization.NumberStyles; its exact expected stdout is 1.5.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

Console.WriteLine(decimal.Parse("1.5", NumberStyles.Number, CultureInfo.InvariantCulture));

Result

1.5

The complete program actually uses `System.Globalization.NumberStyles`; its exact expected stdout is `1.5`.

Sources