Using Round function in C# and VB.Net

Last Reply one year ago By kalpesh

Posted one year ago

the pointable value grether then 0 then i want to value = value+1

var a=12.10;

var b=12.1;

var c=12.50

var d=12.00

 

resultA=13;

resultB=13;

resultC=13;

resultd=12;

how to use round function ??

You are viewing reply posted by: kalpesh one year ago.
Posted one year ago

Refer the below sample code for your reference and implement it as per your code logic.

C#

var testValue = 12.10;
int result;
int number = Convert.ToInt32(testValue.ToString().Split('.')[0]);
int decimalPointvalue = testValue.ToString().Split('.').Length > 1 ? Convert.ToInt32(testValue.ToString().Split('.')[1]) > 0 ? Convert.ToInt32(testValue.ToString().Split('.')[1]) : 0 : 0;
result = number + decimalPointvalue;

VB.Net

Dim testValue = 12.10
Dim result As Integer
Dim number As Integer = Convert.ToInt32(testValue.ToString().Split("."c)(0))
Dim decimalPointvalue As Integer = If(testValue.ToString().Split("."c).Length > 1, If(Convert.ToInt32(testValue.ToString().Split("."c)(1)) > 0, Convert.ToInt32(testValue.ToString().Split("."c)(1)), 0), 0)
result = number + decimalPointvalue

Output

13