15,846,091 members
See more:
hello,

I am having a small conversion issue for Decimal datatyoe in VB.Net

I am having a variable declared as decimal
VB
```dim var as deciaml
var= 12341234123412.341```

now I need to remove this fraction value and convert it into a whole number. I mean the result I want is 12341234123412341 ( only dot is removed and the 3 digits after dot are retained.)

even if I have the value var= 1234.1, I want the result as 1234100 ( after dot 3 digits sholud come and added to whole number). I know that I can do this by multiplying with 1000 but I want other possibilitis to achive this.

need help urgently.. Thanks
Posted
VJ Reddy 23-May-12 4:38am
Thank you for accepting the solution :)

## Solution 1

I know nothing better than multiply by `1000`. Why don't you like that?

[update]
The following code
VB
```Dim v As Decimal = 100.5
v = v * 1000
Dim s As String = v.ToString("F0")
Console.WriteLine(s)
```

Outputs
`100500`

[/update]

v2
derek9999 21-May-12 6:02am
I agree with CPallini. Unless you want to get bogged down with string formatting then multiplying by 1000 is the way to go.
Naveen_143 21-May-12 6:46am
When i am multiplying the decimal variable with 1000, in window server with .netframe work, .000 is getting appended to the value. I mean if var = 100.5 and when i am doing var = var * 1000 gives me 100500.000 and when I am converting this to string the value is becoming 100500.000 which is an unwanted result for me. The end result i want is 100500 only as a string.
Naveen_143 21-May-12 7:28am
I can remove the anwanted result from stirng but i want to know any direct method to do the above function.
VJ Reddy 21-May-12 8:20am
CPallini 21-May-12 8:29am
Thank you.

## Solution 3

Answer 1 by CPallini is good.

In case if you want to convert without multiplying with 1000, then I think the number can be first converted to `String ` representation using `F3 `format and then the `.` may be replaced with `""` as shown below
VB
```Dim var as Decimal =  1234.1D
Dim varString as String = var.ToString("F3").Replace(".","")
Console.WriteLine(varString)

'Output
'1234100```

v2
Maciej Los 21-May-12 8:41am
VJ Reddy 21-May-12 8:42am
Thank you, losmac :)

## Solution 4

All other solutions other than multiplying by 1000 are going to be much slower, so if you need to do this lots and lots of times, that's your best method.

Top Experts
Last 24hrsThis month
 k5054 40 KarstenK 10 Dave Kreskowiak 10 CPallini 10 OriginalGriff 10
 OriginalGriff 2,028 Richard Deeming 875 Dave Kreskowiak 591 Graeme_Grant 539 Richard MacCutchan 485

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900