.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Fix No Of decimal Places in a given number
 

Fix No Of decimal Places in a given number

Hi All,

Ihave a number whcih is comming in the form of String.

Eg: 56.6644897846454 or 86.9999999

i require only first two numbers after decimal point with out rounding the number.

Thanks in Advance

Raghuram
Raghuram Raichooti

string STR1 = "56.6644897846454";

string[] STR2 = regex.split(STR1, ".");

your STR[0] will be 56 only..

Popeye the sailorman
This is one way:

string s = "56.6694897846454";
decimal result = ((int)(decimal.Parse(s) * 100m)) / 100m;

Stuart Dunkeld

string STR1 = "56.6644897846454";

string[] STR2 = regex.split(STR1, ".");

your STR[0] will be 56 only..

Popeye the sailorman
This is one way:

string s = "56.6694897846454";
decimal result = ((int)(decimal.Parse(s) * 100m)) / 100m;

Stuart Dunkeld

Isolved it , but here is one more turn around solution.

Eg: 123456789.987654321

String tvar, var;

tvar = (var.IndexOf('.') + 3).ToString();
tvar = var.Substring(0, int.Parse(tvar));
TextBox4.Text = tvar;

Results: 123456789.98

Raghuram Raichooti

Raghuram Raichooti

You can use google to search for other answers

Custom Search

More Threads

• Chaning Culture for dll project
• Invoke SetPassword C# LDAP provider...Whos got the fix??
• Treeview problem
• Static Interfaces
• Help transmitting files asynchronously
• user control in C#
• Testing ASP.NET authentication in MSSQL developer edition environment
• FileAttributes.Hidden and FileMode.Create
• Determine space available on a network drive
• transform DateTime into Julian day