Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: None  |  size: 0.61 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function formatPctThreeSigFigs() {
  2.  
  3.   /* Formats selected numeric cells as a percentage with three significant figures.
  4.    *
  5.    * Author: Raneath Nor (raneath@gmail.com)
  6.    * Date:   5/31/2011
  7.    */
  8.  
  9.   var ss = SpreadsheetApp.getActiveSpreadsheet();
  10.   var range = ss.getActiveRange();
  11.  
  12.   var rows = range.getNumRows();
  13.   var cols = range.getNumColumns();
  14.   for(var row = 1; row <= rows; row++) {
  15.     for(var col = 1; col <= cols; col++) {
  16.       var cell = range.getCell(row, col);
  17.       var value = cell.getValue();
  18.       if(typeof(value) == 'number') {
  19.         cell.setNumberFormat("#.###%");
  20.       }
  21.     }
  22.   }
  23. }