将String转换为带格式的Double [英] Convert String to Double with format

查看:116
本文介绍了将String转换为带格式的Double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家,

我将字符串转换为双精度字有一个问题.
我有这样的字符串(123456789),我想将其转换为这样的double(123,456,789.00).

有人知道如何格式化吗?

谢谢

TONY

解决方案

使用Double.TryParse
将字符串转换为双精度
但是,另一个要求不是双精度数,而是一个双精度数在字符串中表示为两个DP的局部表示形式.

语言环境规定了分组,分组分隔符和DP字符,即在法国该字符串为123.456.789,00

您可以使用 FormatNumber [ 私有 Sub Form1_Load(发送方 As 对象,以及 As EventArgs) Dim strValue As 字符串 = " Dim d As Double = 0 如果 [ Double ].TryParse(strValue,d)然后 MessageBox.Show(d.ToString(" ,CultureInfo.InvariantCulture)) 结束 如果 结束


Hi experts,

I have one problem with convert string to double.
I have string like this (123456789) and i want to convert it to double like this (123,456,789.00).

Does anyone know how to format like this?

Thanks

TONY

Turning that string into a double is done with Double.TryParse

However, that other requirement is NOT a double, it''s a local representation of that double, in a string, to two DP

Locale dictates grouping, grouping separator and DP character, i.e. that string would be 123.456.789,00 in France

You''d use
FormatNumber[^] to get that


Hi,

What you want is to convert this string to double and then display it in your format. To achieve this you may try this code:

Private Sub Form1_Load(sender As Object, e As EventArgs)
    Dim strValue As String = "123456789"
    Dim d As Double = 0
    If [Double].TryParse(strValue, d) Then
        MessageBox.Show(d.ToString("0,0.00", CultureInfo.InvariantCulture))
    End If
End Sub


这篇关于将String转换为带格式的Double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆