Critical Developers

Programmers Knowledge Base

Shorten Number to 1K, 1Lac, 1Cr using C#

        // Shorten Number to 1K, 1Lac, 1Cr
        public static string ShortNum(decimal? val)
        {
            string unit = string.Empty;
            string str = string.Empty;
            if (val >= 10000000)
            {
                val = (val / 10000000);
                str = string.Format("{0:0.00}", val);
                unit = "Cr(s)";
            }
            else if (val >= 100000)
            {
                val = (val / 100000);
                str = string.Format("{0:0.00}", val);
                unit = "Lac(s)";
            }
            else if (val >= 1000)
            {
                val = (val / 1000);
                str = string.Format("{0:0.00}", val);
                unit = "K(s)";
            }
            else
            {
                str = string.Format("{0:0.00}", val);
            }
            //
            if (str.EndsWith("00"))
            {
                str = ((int)val).ToString();
            }
            //
            if (!string.IsNullOrEmpty(unit))
                str = str + " " + unit;
            //
            return str;
        }

Check if any input element has a value in a div/form using jQuery

Check if any input element has a value in a div/form using jQuery

function fnCheckInputHasValue()
{
var isvalpresent = false;
                        $("div#mydiv").find(":input").each(function () {
                            var type = $(this).attr("type");
                            //alert(type);
                            var $this = $(this);
                            if ($this.is("input")) {
                                if (type == "text") {
                                    var val = $(this).val().trim();
                                    if (val != "") {
                                        isvalpresent = true;
                                    }
                                }
                                //
                                if (type == "checkbox") {
                                    if ($(this).is(":checked")) {
                                        isvalpresent = true;
                                    }
                                }
                                //
                                if (type == "radio") {
                                    if ($(this).is(":checked")) {
                                        isvalpresent = true;
                                    }
                                }
                            }
                            //
                            if ($this.is("select")) {
                                var val = $(this).val().trim();
                                if (val != "" && val != "Select") {
                                    isvalpresent = true;
                                }
                            }
                            //
                            if ($this.is("textarea")) {
                                var val = $(this).val().trim();
                                if (val != "") {
                                    isvalpresent = true;
                                }
                            }
                        });

                        if (isvalpresent == false) {
                            // code
                        }

}