---
title: "js实现小数转百分比"
author: "deejay"
date: "2011-12-26T15:05:57Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2011-12-26T15:05:57Z"
id: 1326582
url: "https://deejay.iteye.com/blog/1326582"
---

Number.prototype.toPercent = function(n){n = n || 0;return ( Math.round( this * Math.pow( 10, n + 2 ) ) / Math.pow( 10, n ) ).toFixed( n ) + '%';}  
var A=0.358975, B=0.25554;  
 alert(\[A, A.toPercent(3), B, B.toPercent()].join('\\n'));