Welcome aboard! We are happy you are here and wish you good net-raft!
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Class1.cs" Inherits="_Default" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(ShortenNumbers(12635));
}
</script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
</body>
</html>
// put into Class1.cs
using System;
using System.Web;
using System.Web.Services;
using System.Globalization;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string ShortenNumbers(long num)
{
if (num >= 100000000) {
return (num / 1000000D).ToString("0.#M");
}
if (num >= 1000000) {
return (num / 1000000D).ToString("0.##M");
}
if (num >= 100000) {
return (num / 1000D).ToString("0.#k");
}
if (num >= 10000) {
return (num / 1000D).ToString("0.##k");
}
return num.ToString("#,0");
}
}
The most helpful C# solutions