Question: I recently started learning AngularJS, and I have the following sample code that does a REST callout from a Visualforce page - the code does a successful callout.
My question: In the 'app.config' where we provide the Authorization header as a string value ('BASIC base64Hash'), base64Hash being the username:password hash, how is this secure? If I open up the page and hit inspect, I can grab the hash and decrypt the base64 to get the username:password.

P.S: Keep in mind that I recently got into AngularJS, and I know that the following procedure for a REST callout from AngularJS may not be the best practice. Which is why the question. :)

```
<apex:page standardStylesheets="false" showHeader="false">
    <html ng-app="hello" lang="en">
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script>
            <script>
                // define the app
                var demoApp = angular.module('hello', []);
                demoApp.config(['$httpProvider', function($httpProvider) {
                    $httpProvider.defaults.headers.common['Authorization'] = 'BASIC base64Hash';
                }]);
                demoApp.controller('helloController', function($scope, $http){
                    $http({
                        method: "GET",
                        url: "ENDPOINT URL",
                    }).then(function mySuccess(response){
                        $scope.apiResponse = response.data;
                    }, function myError(response){
                        $scope.apiResponse = response.statusText;
                    });
                });
            </script>
        </head>
        <body ng-controller="helloController">
            <div>
              {{apiResponse}}
            </div>
        </body>
    </html>
</apex:page>

```

Answer: 
The data type that gives you fine-grained control over precision is `Decimal`. For example, if you wanted to have 30 decimal places after the divide this:

```
Decimal d = 5;
d = d.divide(3, 30);
System.debug('>>> ' + d);

```

outputs this:

```
>>> 1.666666666666666666666666666667

```

Take a look at the [Decimal documentation](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_decimal.htm) to see the various methods available that allow you to control precision.

Decimal is significantly different from Double or Float: they represent numbers using a fixed number of bits and most CPUs have hardware support for calculations using them. Decimal (BigDecimal in Java) on the other hand is implemented in software and handles an open ended number of digits *exactly*. Unless you are doing massive amounts of calculations the slower performance of Decimal is irrelevant.

If doing calculations involving money, Decimal is a good choice to exactly control rounding and avoid losing precision with large numbers.

On your specific question, when a calculation discards some digits they are not going to re-appear. Financial algorithms often have specific rounding rules defined as part of their specification to address this e.g. [COMPOUND INTEREST](http://sites.csn.edu/istewart/Math120/Consumer/compound_interest.html).
Decimal, Float or Double data type always lose precision when multiplied, added or divided.

**Regardless of programming language** we use, this behavior is universal. I would like you to go through following post if you want to understand in detail.

[What Every Computer Scientist Should Know About Floating-Point Arithmetic](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)

Otherwise, this is easy one, however addition doesn't apply to Salesforce because we have bigger precision data type - [Floating point guide](http://floating-point-gui.de/)

**Decimal v/s Double**

`Double` are typically 64 bit number but Decimal is 128 bit. With both types we can have unexpected results based on at which size the result is finished.

Take following example:-

```
Decimal total = 8.0/3.0; // 2.66666666666666666666666666666667
Decimal total2 = total*3.0; // 8.000000000000000000000000000000010
Double totald = 8.0/3.0; // 2.6666666666666665
Double totald2 = totald*3.0; // 7.999999999999999
System.debug(' ===>'+ (total));
System.debug(' ===>'+ (total2));
System.debug(' ===>'+ (totald));
System.debug(' ===>'+ (totald2));

```

In above example `Decimal` had the greater memory than `Double` so, ended up in more detailed result. This further result into some unexpected result.