本文介绍了vb.net'控制小数位置以逗号分隔的值'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个逗号分隔值,即12.03E + 03,15000E + 03。

I have a comma separated value which is 12.03E+03 , 15.000E+03.

如何将它们更改为2位小数?

How to change the them to 2 decimal places?

请回复我 

pls reply me 

推荐答案

试试这个。获取格式为2位小数的字符串列表。

Try this. Gets a list of strings formated to 2 decimal places.

Dim res As New List(Of String) Dim v As String = "12.03E+03 , 15.000E+03" For Each s As String In v.Split(","c) res.Add(GetDouble(s).ToString("#.00")) Next

   函数GetDouble(s As String)As Double
        '将字符串更改为Double(或零)
        Dim v As Double = 0.0
       如果Double.TryParse(s,v)那么返回v
       退货0.0
   结束功能

    Function GetDouble(s As String) As Double
        ' change string to Double (or zero)
        Dim v As Double = 0.0
        If Double.TryParse(s, v) Then Return v
        Return 0.0
    End Function


这篇关于vb.net'控制小数位置以逗号分隔的值'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 19:55