/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Double.ToString/vb/roundtripex1.vb
38 строк
2 KB
Andy (Steve) De George
Fix code example output (#43162)
23 окт 2024, 18:40
Не верифицирован
23 окт 2024, 18:40
eff72a7
Код
Авторство
О чём код?
' Visual Basic .NET Document Option Strict On ' <Snippet5> Imports System.Globalization Module Example Public Sub Main() Console.WriteLine("Attempting to round-trip a Double with 'R':") Dim initialValue As Double = 0.6822871999174 Dim valueString As String = initialValue.ToString("R", CultureInfo.InvariantCulture) Dim roundTripped As Double = Double.Parse(valueString, CultureInfo.InvariantCulture) Console.WriteLine("{0:R} = {1:R}: {2}", initialValue, roundTripped, initialValue.Equals(roundTripped)) Console.WriteLine() Console.WriteLine("Attempting to round-trip a Double with 'G17':") Dim valueString17 As String = initialValue.ToString("G17", CultureInfo.InvariantCulture) Dim roundTripped17 As Double = double.Parse(valueString17, CultureInfo.InvariantCulture) Console.WriteLine("{0:R} = {1:R}: {2}", initialValue, roundTripped17, initialValue.Equals(roundTripped17)) End Sub End Module ' If compiled to an application that targets anycpu or x64 and run on an x64 system, ' the example displays the following output: ' Attempting to round-trip a Double with 'R': ' .NET Framework: ' 0.6822871999174 = 0.68228719991740006: False ' .NET: ' 0.6822871999174 = 0.6822871999174: True ' ' Attempting to round-trip a Double with 'G17': ' 0.6822871999174 = 0.6822871999174: True ' </Snippet5>