How to show number with two decimal places in AngularJS 1.0


How to show number with two decimal places in AngularJS 1.0

Introduction:
            Here  solution of display number with 2 decimal places in AngularJs and Html view. So first I find all solutions. Finally I find out shortest trick to display number with 2 decimal places in angularJS.

Solution Steps:

Step 1: Create simple html page.
 index.html
            <html>
<head>
            <title>Decimal places by RAJESH GAMI</title>
</head>

<body>
                        <div>
                         <p> Hello I am Rajesh Gami, Here is solution of display number with two decimal places using AngularJS </p>

                                    <h3></h3>
                        </div>
</body>
</html>
Step 2: Now add script link of AngularJS under <head> tag in our index.html page
            Angular.min.js :  

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>

Step 3: Now we add angular-animate.js under <head>tag.
Angular animate use for animation in html, there are two way to make use of animation 1. CSS and  2.JavaScript. When we use angular animate.js our output will display using AngularJS 1.0.

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-animate.js"></script>

Step 4: now we give name of data-ng-app and data-ng-controller in html page.
            See like this:
Index.html
<html data-ng-app="DecimalModule">
<head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>  
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-animate.js"></script>
</head>
 

<body data-ng-controller="DecimalController">
<div>
                         <p> Hello I am Rajesh Gami, Here is solution of display number with two decimal places using AngularJS </p>

                                    <h3></h3>
            </div>
</body>
</html>

Step 5: Now we create new AngularJS file name: controller.js And save file in your folder
Step 6 :  Now first add app module in controller.js
            Controller.js
            (function () {
        app = angular.module("DecimalModule", ['ngAnimate']);
    })();       
In above module code in DecimalModule  module name, we give this name in html file(data-ng-app="DecimalModule").
And ngAnimate  use for animation. The ngAnimate module provides support for CSS-based animations (keyframes and transitions) as well as JavaScript-based animations via callback hooks. Animations are not enabled by default, however, by including ngAnimate the animation hooks are enabled for an AngularJS app.

Step 7:  Now we create controller in controller.js file after angular-module.

app.controller("DecimalController", function ($scope)
{
});

Step 8: Now we add logic for two decimal spaces in app.controller
1.       First add variable Result
$scope.Results = "";

2.       Now we add percentage variable and store percentage

var percentage = (6 * 100) / 7;           
answer is : 85.71428571428571.
but we want to display only 85.71 so we add below code

3.      Now variable percentage do as fixed for two decimal places.
var result = percentage.toFixed(2);

this code use to fixed two decimal place.
Now answer is : 85.71

4.      Now we store last result in another scope.Result.
                            $scope.Results = "Your Result: " + result + " %";

Complete Controller.js file
Controller.js
(function () {
        app = angular.module("DecimalModule", ['ngAnimate']);
    })();


    app.controller("DecimalController", function ($scope) {
        $scope.Results = "";

        var percentage = (6 * 100) / 7;
        var result = percentage.toFixed(2)

        $scope.Results = "Your Result: " + result + " %"; 

});


Step 9: Now add controller.js in to html script.

<script type="text/javascript" src="controller.js"></script>

Step 10: Now we want to display our result so that,  add {{ Result }} in our html page in any tag in between<body>.
<h3>{{Results }}</h3>

Complete index.html page code.
Index.html
<html data-ng-app="DecimalModule">
<head>
    <title>Decimal places by RAJESH GAMI</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
    <script type="text/javascript" src="controller.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-animate.js"></script>

</head>

<body data-ng-controller="DecimalController">
    <div>
        <p> Hello I am <b>Rajesh Gami</b>, Here is solution of display number with two decimal places using AngularJS </p>
        <p> {{Results }}</p>
    </div>
</body>
</html>

Conclusion:
           Here I will try to easiest way for display number two decimal places. I hope you guys will help this angularJS code and very well understand this code. If any doubt then tell me I will solve it.

















RDLC Report in Asp.net MVC - RAJESH GAMI

RDLC Report Created by RAJESH GAMI (Facebook: /Rajesh Gami ... Instagram: rajesh_gami12)


.............................................................................................................
If we need Multiple table in create RDLC report then Create view in SQL server.

==> In SQL server first explore Database then select View and press Right click => New view then select table what we need (e.x  one is Primary.Key second is F.K etc) then select Column check box if we need to all column then select * All Columns otherwise select manualy. then SAVE (Ctrl + S) and give Name of View (e.x Product_view). Now complete work in SQL server Lets start Visual studio.

==> New Project => select Web Application => select MVC 

==> Add NuGet Package Manager so Click on Tools in Visual studio.

==> Tools => NuGet Package Manager => Package Manager Console. then show bottom in visual studio One window box open then our install path paste after PM> 

now take some time then one another paste install package for SQL server 


Now Create New folder in project and give Name RDLC then right click on RLDC folder and Add=>new item => Reporting => Report wizard then give name and then Ok.
 Now create New Connection => select view 

=> Name: e.x  Product-Dataset [Choose your name ]
=> Data Source: e.x RAJ_DashboardDatSet [Select your dataset what we create]
=> Available dataset: e.x Product_view [Select your view dataset] 
then select NEXT 

xsd file create automatically in VS show that... Double click on  RAJ_DashboardDatSet.xsd 
Show our product view. if not show Product_view then drag and Drop from  server explorer.

==> Now add another new file for RDML so Right click on our project then => Add => new item then => select Data then => Select LINQ to SQL classes then give name and OK
now Drag and drop our view (Product_View ) from server explorer 
==> Select server explorer in left side of VS above or Below tool box. if not show Server Explorer then select View and Select Server Explorer .
=> Server Explorer => Data Connection => your database => view => then Drag and Drop your view on rdml side..

==> Create Controller e.x ProductController. show below image



After create controller Paste below code:
-----------------------------------------------------------------------------------------

using Microsoft.Reporting.WinForms;     // must add this nameSpace 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace My_ReportDemo.Controllers
{
    public class ProductController : Controller
    {
        // GET: Product
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult ProductPrint()
        {

            RDMLDataContext rdlcdb = new RDMLDataContext();
            LocalReport lr = new LocalReport();
            string mpath = Server.MapPath("~/RDLC/");   // Path // Write your path
            lr.ReportPath = mpath + "Report1.rdlc";   // RDLC file name //So write your Rdlc file name
            lr.EnableExternalImages = true;
            string name = "branch_name"; //For 
            ReportDataSource rd = new ReportDataSource("Product_DataSet", rdlcdb.Product_views.OrderBy(s => s.Product_Name).ToList());

            ReportParameter rp1 = new ReportParameter("parameter", name); //"parameter" is parameter name so give your Parameter name what you have
            lr.SetParameters(new ReportParameter[] { rp1 });
            lr.DataSources.Add(rd);

            string reporttype = "PDF"; //"PDF" write your file ex. Excel,PDF,Doc etc

            // Do not change below Codding Only copy paste
            string mimtype;   
            string encoding;
            string filenameextansion;

            string deviceInfo =

            "<DeviceInfo>" +
            "  <OutputFormat>PDF</OutputFormat>" +
            "  <PageWidth>7.8in</PageWidth>" +
            "  <PageHeight>11in</PageHeight>" +
            "  <MarginTop>0.5in</MarginTop>" +
            "  <MarginLeft>.5in</MarginLeft>" +
            "  <MarginRight>.5in</MarginRight>" +
            "  <MarginBottom>0.5in</MarginBottom>" +
            "</DeviceInfo>";

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            renderedBytes = lr.Render(
                reporttype,
                deviceInfo,
                out mimtype,
                out encoding,
                out filenameextansion,
                out streams,
                out warnings);


            return File(renderedBytes, mimtype);
        }
    }
}

-----------------------------------------------------------------------------------------

Now Add View for Index.

=> Right click on Index => Add view 

select Empty (Without Model) and then Add

paste below code:


Index.cshtml

-------------------------------------------------------------------------------------
@{
    ViewBag.Title = "Index";
}

<h2>Product Data</h2>

<a href="~/Product/ProductPrint">Print</a>

---------------------------------------------------------------------------------------

above code in Product is Controller name and ProductPrint is Action name in Controller



Now select .rdlc file and set your Table data.

show below Image




if Image is not show clearly then right click on image and open new tab



Now run the project and see the result
=================================================
























RAJESH GAMI - Blog

Digital Signature Pad in Angular | RAJESH GAMI

  What is Signature Pad? Signature Pad could be a JavaScript library for drawing fancy signatures. It supports HTML5 canvas and uses variabl...