Hi Fellas,
Here i’m going to explain the workaround for formatting a number inside JSP using Struts 2 OGNL Tag. But, before we directly go to the solution, we have to know something about “MessageFormat” and “NumberFormat” classes. Anyway I think this is not the right place to explain.
The way to format a number in a JSP using OGNL is just simple as that.
The stuff inside the first set of braces is the formatting pattern. It says
{ArgumentIndex , FormatType , FormatStyle}; which means:
0 – Argument Index
number – Format Type
#,##0.00 – Format Style
The stuff inside the second set of braces is the actual value to be displayed.
For example, if you assign amount=5851259.52, the output will be 5,851,259.52.
You can get more about MessageFormat class from here and read more about NumberFormat class by clicking here.
Also, you can read Apache Struts 2 Documentation about Formatting Dates and Numbers here.
Thanks..
9.939434
76.241770
Published by
Deepesh Darshan K R
I am Me.
In all the world, there is no one else exactly like me.
Everything that comes out of me is authentically mine, because I alone chose it.
I own everything about me: my body, my feelings, my mouth, my voice, all my actions, whether they be to others or myself.
I own my fantasies, my dreams, my hopes, my fears.
I own my triumphs and successes, all my failures and mistakes. Because I own all of me,
I can become intimately acquainted with me. By so doing, I can love me and be friendly with all my parts.
I know there are aspects about myself that puzzle me, and other aspects that I do not know -- but as long as I am friendly and loving to myself, I can courageously and hopefully look for solutions to the puzzles and ways to find out more about me.
However I look and sound, whatever I say and do, and whatever I think and feel at a given moment in time is authentically me. If later some parts of how I looked, sounded, thought, and felt turn out to be unfitting, I can discard that which is unfitting, keep the rest, and invent something new for that which I discarded.
I can see, hear, feel, think, say, and do.
I have the tools to survive, to be close to others, to be productive, and to make sense and order out of the world of people and things outside of me.
I own me, and therefore,
I can engineer me.
I am me, and
.
.
.
.
.
.
.
.
.
.
I am Okay.
Haha.. Let it go..
I am a software engineer working in a MNC here at Kochi itself, specialized on J2EE platform, dribbling with frameworks like struts, hibernate etc.
View all posts by Deepesh Darshan K R
I have number=0833888999 and I want to format it as 0833 888 999 .
How to format the number so that 0 remains at first place