String : Get first 3 characters after the dot

Hello,

I have the following values in strings

  • 124.98765
  • 113.450988

But i only want 124.987, 113.450 , just till the 3rd decimal point.

I have to use split string but i’m having trouble writing the code for it.

Thank you for the help.

You can split the string based on . and use substring method to get those 3 characters after dot.

Or you can use Math.Round(value,3) method

Can you tell the split string code for it please ?

Hi @Yugal_Raju

try this way,

this will give the round of your input

Math.Round(CDbl(β€œ124.98765”),3)

Math.Round(CDbl(β€œ113.450988”),3)

image

try another way if you don’t want round of

Math.Floor(CDbl(β€œ124.98765”) * 1000) / 1000

Math.Floor(CDbl(β€œ113.450988”) * 1000) / 1000

image

Regards,
Gowtham K

varStr.Substring(0,varStr.IndexOf(".")+4)
1 Like

@Yugal_Raju,

Math.Round is the best practice here.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.