using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Swarmops.Frontend.Automation
{
public partial class Formatting : DataV5Base
{
protected void Page_Load (object sender, EventArgs e)
{
// This page exists only for its web methods, which are called by Ajax.
}
///
/// Returns a culturally-formatted integer with thousands separators.
///
/// The integer to format.
/// The formatted integer for display.
[WebMethod]
public static string FormatInteger(int input)
{
GetAuthenticationDataAndCulture();
return input.ToString("N0");
}
///
/// Returns a culturally-formatted double with thousands separators and two decimals.
///
/// The double to format.
/// The formatted double for display.
[WebMethod]
public static string FormatCurrency(double input)
{
GetAuthenticationDataAndCulture();
return input.ToString("N2");
}
[WebMethod]
public static AjaxInputCallResult FormatCurrencyString(string input)
{
double outParse = 0.0;
bool success = false;
if (Double.TryParse(input, NumberStyles.AllowThousands | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture, out outParse))
{
success = true;
}
else if (Double.TryParse(input, NumberStyles.AllowThousands | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out outParse))
{
success = true;
}
if (!success)
{
return new AjaxInputCallResult {Success = false};
}
return new AjaxInputCallResult {Success = true, NewValue = outParse.ToString("N2")};
}
}
}