Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

JavaScript: Format 1000.470334 --> 1,000.48


This topic is 7850 days old. Please don't post here. Open a new topic instead.

Recommended Posts

hello people!

I know that for the most part [FMP-Field:name,format] should work but here is a nice script that does the mentioned format when CDML is not available:

original page source:http://developer.irt.org/script/number.htm


	<script>

		function outputMoney(number) // script source -->http://developer.irt.org/script/number.htm

		{

    		return outputDollars(Math.floor(number-0) + '') + outputCents(number - 0);

		}



		function outputDollars(number) 

		{

			if (number.length <= 3)

				return (number == '' ? '0' : number);

			else {

				var mod = number.length%3;

				var output = (mod == 0 ? '' : (number.substring(0,mod)));

				for (i=0 ; i < Math.floor(number.length/3) ; i++) {

					if ((mod ==0) && (i ==0))

						output+= number.substring(mod+3*i,mod+3*i+3);

					else

						output+= ',' + number.substring(mod+3*i,mod+3*i+3);

				}

				return (output);

			}

		}

		

		function outputCents(amount) {

			amount = Math.round( ( (amount) - Math.floor(amount) ) *100);

			return (amount < 10 ? '.0' + amount : '.' + amount);

		}

	</script>

......

document.write(outputMoney(1000.470334));

my little contrib. if anyone needed to know

Link to comment
Share on other sites

This topic is 7850 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.