Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div ng-app="app" ng-controller="appCtrl">
  <span class="jumbotron title">
     <h3>{{title}}</h3>

    <span ng-repeat="number in numbers">
      <b  class="badge badge-primary bigger" > 
        {{number.value | formatNumber: number.format}}
      </b>
    </span>
  </span>

</div>
              
            
!

CSS

              
                body {
  text-align: center;
}
.title {
  background-color: #cccfff;
  display: block;
  color: rgb(0, 100, 255);
}

.bigger {
  font-size: 2em;
  display: inline-block;
  margin: .1em;
}
              
            
!

JS

              
                angular.module('app', [])
  .config(() => {})
  .run(() => {})

angular.module('app')
  .controller('appCtrl', appCtrl)

angular.module('app')
  .filter('formatNumber', formatNumber)

// number filter/pipe based on d3.format()
// https://github.com/d3/d3-format
// a few examples
// d3.format(".0%")(0.123);  // rounded percentage, "12%"
// d3.format("($.2f")(-3.5); // localized fixed-point currency, "(£3.50)"
// d3.format("+20")(42);     // space-filled and signed, "                 +42"
// d3.format(".^20")(42);    // dot-filled and centered, ".........42........."
// d3.format(".2s")(42e6);   // SI-prefix with two significant digits, "42M"
// d3.format("#x")(48879);   // prefixed lowercase hexadecimal, "0xbeef"
// d3.format(",.2r")(4223);  // grouped thousands with two significant digits, "4,200"
class Format {
  constructor () {}
  number (n, f) {
    
    const format = f || '1.0?s'
    
    let number
    
    // Put business logic here
    switch (format) {
      case '$1.00':
        number = d3.format('$.2s')(n)
        break
      case '$1,000.00':
        number = d3.format('$,2f')(n)
        break
      case '1.0?s':
        if (/\.0/.test(d3.format('.2s')(n))) {
          number = d3.format('~s')(n)
        } else {
          number = d3.format('.2s')(n)
        }
        break
      default:
        number = d3.format(format)(n)
    }
    
    console.log('run', [n, number])
    
    return number.replace(/G/, "B").toUpperCase()
  }
}

function formatNumber () {
  return new Format().number
}

appCtrl.$inject = ['$scope']
function appCtrl ($scope) {
  $scope.title = 'Fun with numbers 🇺🇸'
  const thousand = 1500
  const thousands = 2333
  const million = 1000000
  const millpoint5 = 1555000
  const billion = 10000000000
  const trillion = 1000000000000
  
  const BigMoney = 15000000.99
  const money = 1000.23
  
  $scope.numbers = [
    {value: thousand},
    {value: thousands},
    {value: million},
    {value: millpoint5},
    {value: billion},
    {value: BigMoney, format: '$1.00'},
    {value: money, format: '$,'},
    {value: trillion}
  ]
}
              
            
!
999px

Console