Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function float(answer, x, y) {
- var count = yLength = xLength = 0;
- if (x < 1 && x > -1) {
- if (x > 0) {
- while (x < 1) {
- x = x * 10;
- count++;
- }
- xLength = count;
- }
- if (x < 0) {
- while (x > -1) {
- x = x * 10;
- count++;
- }
- }
- xLength = count;
- }
- if (y < 1 && y > -1) {
- count = 0;
- if (y > 0) {
- while (y < 1) {
- y = y * 10;
- count++;
- }
- yLength = count;
- }
- if (y < 0) {
- while (y > -1) {
- y = y * 10;
- count++;
- }
- yLength = count;
- }
- }
- if (yLength == 0 && xLength == 0) {
- return answer;
- }
- if (yLength >= xLength) {
- return parseFloat(answer).toFixed(yLength);
- }
- if (xLength >= yLength) {
- return parseFloat(answer).toFixed(xLength);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment