I want to receive the number after the decimal dot in the form of an integer. For example, only 05 from 1.05 or from 2.50 only 50 not 0.50
The simplest variant is possibly with Math.truncate()
double value = 1.761
double decPart = value - Math.truncate(value)
string input = "0.55";
var regex1 = new System.Text.RegularExpressions.Regex("(?<=[\\.])[0-9]+");
if (regex1.IsMatch(input))
{
string dp= regex1.Match(input ).Value;
}
There is a cleaner and ways faster solution than the 'Math.Truncate' approach:
double frac = value % 1;
Better Way -
double value = 10.567;
int result = (int)((value - (int)value) * 100);
Console.WriteLine(result);
Output -
56
Why not use int y = value.Split('.')[1];
?
The Split()
function splits the value into separate content and the 1
is outputting the 2nd value after the .
Use a regex: Regex.Match("\.(?\d+)")
Someone correct me if I'm wrong here