Solved

format of a number

Posted on 2015-01-13
4
83 Views
Last Modified: 2015-01-13
Hi,

How can I change this number from

output: 
5,300,000 - 6,500,000
400,000 - 700,000
450,000 - 250,000
but 

this is how I want the output to be:

5.3M - 6.5M 
400K - 700K
450K - 250K




   <cfoutput>#numberformat(GrandFrom2020,'999,999,999,999,999,999,999')#</cfoutput> -
          <cfoutput>#numberformat(GrandTo2020,'999,999,999,999,999,999,999')#</cfoutput>  

Open in new window

0
Comment
Question by:lulu50
  • 2
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
Pravin Asar earned 500 total points
Comment Utility
Hope this works for you.

<cfset x=345000/>
<cfset y = 6500000/>
<cfscript>
      function MyFormatter(number) {
            formatDone = false;
            convertText= "K,M";
            convertFactore="1000,1000000";
            while (!formatDone) {
                  if (number/1000000 > 1) {
                        return "" & (number/1000000) & "M";
                  }
                  else if (number/1000 > 1) {
                        return "" & (number/1000) & "K";
                  }
                  else {
                        return number;
                  }
            }
      }

</cfscript>
<cfoutput>#myformatter(x)#</cfoutput>
<br/>

<cfoutput>#myformatter(y)#</cfoutput>
0
 

Author Comment

by:lulu50
Comment Utility
Pravin

I don't know where to start to thank you

YOU ARE GREAT!!!

WOW What can I say!!!!!!

WOW AGAIN AND AGAIN

GOOD JOB!!!!!!
0
 

Author Closing Comment

by:lulu50
Comment Utility
Thank you for taking the time to help me.
0
 
LVL 28

Expert Comment

by:Pravin Asar
Comment Utility
Thanks for the points
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now