• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

VB.NET Single.ToString方法代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Single.ToString方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Single.ToString方法的具体用法?VB.NET Single.ToString怎么用?VB.NET Single.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Single的用法示例。



在下文中一共展示了Single.ToString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1:

Dim value As Single = 16325.62901
Dim specifier As String
Dim culture As CultureInfo

' Use standard numeric format specifiers.
specifier = "G"
culture = CultureInfo.CreateSpecificCulture("eu-ES")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16325,62901
Console.WriteLine(value.ToString(specifier, CultureInfo.InvariantCulture))
' Displays:    16325.62901

specifier = "C"
culture = CultureInfo.CreateSpecificCulture("en-US")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    $16,325.63
culture = CultureInfo.CreateSpecificCulture("en-GB")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    £16,325.63

specifier = "E04"
culture = CultureInfo.CreateSpecificCulture("sv-SE")
Console.WriteLine(value.ToString(specifier, culture))
' Displays: 1,6326E+004   
 culture = CultureInfo.CreateSpecificCulture("en-NZ")
 Console.WriteLine(value.ToString(specifier, culture))
' Displays:    1.6326E+004   

specifier = "F"
culture = CultureInfo.CreateSpecificCulture("fr-FR")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16325,63
culture = CultureInfo.CreateSpecificCulture("en-CA")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16325.63

specifier = "N"
culture = CultureInfo.CreateSpecificCulture("es-ES")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16.325,63
culture = CultureInfo.CreateSpecificCulture("fr-CA")
Console.WriteLine(value.ToString(specifier, culture))
' Displays:    16 325,63

specifier = "P"
culture = CultureInfo.InvariantCulture
Console.WriteLine((value/10000).ToString(specifier, culture))
' Displays:    163.26 %
culture = CultureInfo.CreateSpecificCulture("ar-EG")
Console.WriteLine((value/10000).ToString(specifier, culture))
' Displays:    163.256 %
开发者ID:VB.NET开发者,项目名称:System,代码行数:51,代码来源:Single.ToString


示例2: Example

Module Example
   Public Sub Main()
      Dim number As Single = 1764.3789
      
      ' Format as a currency value.
      Console.WriteLine(number.ToString("C"))
      
      ' Format as a numeric value with 3 decimal places.
      Console.WriteLine(number.ToString("N3"))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:11,代码来源:Single.ToString

输出:

$1,764.38
1,764.379


示例3: numbers

Dim numbers() As Single = {1054.32179, -195489100.8377, 1.0437E21, _
                           -1.0573e-05}
Dim specifiers() As String = { "C", "E", "e", "F", "G", "N", "P", _
                               "R", "#,000.000", "0.###E-000", _
                               "000,000,000,000.00###"}
For Each number As Single In numbers
   Console.WriteLine("Formatting of {0}:", number)
   For Each specifier As String In specifiers
      Console.WriteLine("   {0,5}: {1}", _
                        specifier, number.ToString(specifier))
   Next
   Console.WriteLine()
Next
开发者ID:VB.NET开发者,项目名称:System,代码行数:13,代码来源:Single.ToString

输出:

Formatting of 1054.32179:
C: $1,054.32
E: 1.054322E+003
e: 1.054322e+003
F: 1054.32
G: 1054.32179
N: 1,054.32
P: 105,432.18 %
R: 1054.32179
#,000.000: 1,054.322
0.###E-000: 1.054E003
000,000,000,000.00###: 000,000,001,054.322      

Formatting of -195489100.8377:
C: ($195,489,100.84)
E: -1.954891E+008
e: -1.954891e+008
F: -195489100.84
G: -195489100.8377
N: -195,489,100.84
P: -19,548,910,083.77 %
R: -195489100.8377
#,000.000: -195,489,100.838
0.###E-000: -1.955E008
000,000,000,000.00###: -000,195,489,100.00

Formatting of 1.0437E+21:
C: $1,043,700,000,000,000,000,000.00
E: 1.043700E+021
e: 1.043700e+021
F: 1043700000000000000000.00
G: 1.0437E+21
N: 1,043,700,000,000,000,000,000.00
P: 104,370,000,000,000,000,000,000.00 %
R: 1.0437E+21
#,000.000: 1,043,700,000,000,000,000,000.000
0.###E-000: 1.044E021
000,000,000,000.00###: 1,043,700,000,000,000,000,000.00

Formatting of -1.0573E-05:
C: $0.00
E: -1.057300E-005
e: -1.057300e-005
F: 0.00
G: -1.0573E-05
N: 0.00
P: 0.00 %
R: -1.0573E-05
#,000.000: 000.000
0.###E-000: -1.057E-005
000,000,000,000.00###: -000,000,000,000.00001


示例4:

Dim value As Single 

value = -16325.62015
' Display value using the invariant culture.
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture))
' Display value using the en-GB culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")))
' Display value using the de-DE culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")))

value = 16034.125E21
' Display value using the invariant culture.
Console.WriteLine(value.ToString(CultureInfo.InvariantCulture))
' Display value using the en-GB culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("en-GB")))
' Display value using the de-DE culture.
Console.WriteLine(value.ToString(CultureInfo.CreateSpecificCulture("de-DE")))
' This example displays the following output to the console:
'       -16325.62015
'       -16325.62015
'       -16325,62015
'       1.6034125E+25
'       1.6034125E+25
'       1,6034125E+25
开发者ID:VB.NET开发者,项目名称:System,代码行数:24,代码来源:Single.ToString


示例5:

Dim number As Single

number = 1.6E20
' Displays 1.6E+20.      
Console.WriteLine(number.ToString())

number = 1.6E2
' Displays 160.
Console.WriteLine(number.ToString())

number = -3.541
' Displays -3.541.
Console.WriteLine(number.ToString())

number = -1502345222199E-07
' Displays -150234.5222199.
Console.WriteLine(number.ToString())

number = -15023452221990199574E-09
' Displays -15023452221.9902.
Console.WriteLine(number.ToString())

number = .60344
' Displays 0.60344.
Console.WriteLine(number.ToString())

number = .000000001
' Displays 1E-09.
Console.WriteLine(number.ToString())
开发者ID:VB.NET开发者,项目名称:System,代码行数:29,代码来源:Single.ToString


示例6:

Dim Done As Boolean = False
Dim Inp As String
Do

    Console.Write("Enter a real number: ")
    Inp = Console.ReadLine()
    Try
        S = Single.Parse(Inp)
        Console.WriteLine("You entered " + S.ToString() + ".")
        Done = True
    Catch E As FormatException
        Console.WriteLine("You did not enter a number.")
    Catch E As Exception
        Console.WriteLine("An exception occurred while parsing your response: " + E.ToString())
    End Try
Loop While Not Done
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:Single.ToString



注:本文中的System.Single.ToString方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET Single.TryParse方法代码示例发布时间:2022-05-24
下一篇:
VB.NET SByte.CompareTo方法代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap