Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB
i have been analysing a code in that a double value is being changed to string and is split and then stored into database.
 

ex:dim a as double=123.23
dim b() as string
b=a.tosting().split(".")
 
this can be done like this aslo
i.e
dim a as double=123.23
dim b as string
b=a.tostring()
 
can anyone plz help me find what is the use of split() in this case.
Posted 16-Sep-12 17:06pm
Comments
Sergey Alexandrovich Kryukov at 16-Sep-12 23:51pm
   
First, what's the problem? did you simply read the MSDN help on it? -- would be too trivial.
Second, why would you use double.ToString? Chances are, you don't need it. It's always good to explain your goals, to get better answers.
--SA
Member 8953399 at 17-Sep-12 0:51am
   
in my application values are stored in database by conversion of double value to string.if double can be directly changed into string using tostring() then why split() is used.i want the usage of split used here.
b = a.ToString().Split("."C)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
see this sample:
Dim a As Double = 123.23
Dim b As String() = Nothing
b = a.ToString().Split("."C)
Dim part1 As String = b(0)
Dim part2 As String = b(1)
MessageBox.Show(part1 + "  " + part2)
Basically in this case, split separates the part before and after the period, so that in b(0) you have "123" and in b(1) you have "23". Please take care of regional settings where 123.23 may be displayed as 123,23 (e.g. this is the case in Germany).
  Permalink  
Comments
Member 8953399 at 17-Sep-12 6:42am
   
plz give the usage of split() here.
JF2015 at 17-Sep-12 6:47am
   
It is just to separate the part before and after the period.
Member 8953399 at 17-Sep-12 6:50am
   
this conversion of double to string can be done using tostring().but still why we require split().plz help
JF2015 at 17-Sep-12 7:31am
   
You don't need it. It may just be used if you want to have two separate strings. One before and one after the period.
Member 8953399 at 17-Sep-12 12:38pm
   
plz dont mind bcz the code am analysing this code and in that split is used.
 
Dim avgBVsplit(2) As String
avgBVsplit = SumPC.ToString().Split(".")
If avgBVsplit.Count = 2 Then
If avgBVsplit(1).Length > 2 Then
frmRMM.tslPC.Text = "PC(Sum) : " + avgBVsplit(0) + "." + avgBVsplit(1).Substring(0, 2)
Else
frmRMM.tslPC.Text = "PC(Sum) : " + SumPC.ToString()
End If
Else
frmRMM.tslPC.Text = "PC(Sum) : " + SumPC.ToString()
End If

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 195
2 Prakriti Goyal 177
3 jlopez788 134
4 Kruti Joshi 117
0 OriginalGriff 6,742
1 Sergey Alexandrovich Kryukov 5,479
2 Maciej Los 3,474
3 Peter Leow 3,313
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 16 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100