开发者

how to use the round maths function in asp.net?

I am use the textbox value like 1455.23, use the round function my output is 0000145523 but customer not enter float values like 1234 my output is 0000123400 pls give me suggestion my code is format.cs

public bool formatAmount(float flAmount, out string strOutput)
{
  bool bval = false;
  float rounded = (float)Math.Round(flAmount, 2);
  if(rounded!=null)
  {
    flAmount = flAmount * 100;
    strOutput = Convert.ToString(flAmount);
    bVal = true;
  }

  return bVal;
}

In my asp page code like this

string ods;
float a = Convert.Todecimal(txtSSA.Text);
string sss = oclsUtility.开发者_JAVA技巧formatAmount(a, out ods);


I am assuming you want to ignore the multiplication of 100 part in case the fractional value is not there.

So 1234 in your case is essentially 1234.00 and you need to avoid the 0000123400

float flAmount = 15F;
float rounded = (float)Math.Round(flAmount, 2);
double fractionalval = (rounded - Math.Floor(rounded)) * 100;
if(fractionalval > 0)
   flAmount = flAmount * 100;

After this i presume rest might work and pad it to 10 length string.

This would skip the multiplication if there are fractional parts, hope this is what you need else please edit for additional information.


If I'm understanding you, you need to keep leading 0 if user input is float and if not removes them. You can try this:

int number;
bool result = Int32.TryParse(rounded, out number);
if (result)
{
    // Your number will contain the number with no leading 0
}
else
{
    // Then you have a float.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜