Solved

Control the digits after decimal point in float numbers

Posted on 2009-04-06
11
1,804 Views
Last Modified: 2012-05-06
How I can control the digits after decimal point in float numbers ?

For example I have this number 11.656565 I want to display as 11.65

I need an example in JSP
0
Comment
Question by:bworld
  • 3
  • 2
  • 2
  • +1
11 Comments
 
LVL 26

Expert Comment

by:ksivananth
Comment Utility
use BigDecimal!
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 125 total points
Comment Utility
for e.g.,

new BigDecimal( 11.656565 ).setScale( 2, BigDecimal.ROUND_HALF_UP ).doubleValue() ;
0
 

Author Comment

by:bworld
Comment Utility
ksivananth

I used the previous statement with out.print but I get error as follow
out.print(new BigDecimal(fldValue).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + " %");



HTTP Status 500 - 
 

--------------------------------------------------------------------------------
 

type Exception report
 

message 
 

description The server encountered an internal error () that prevented it from fulfilling this request.
 

exception 
 

org.apache.jasper.JasperException: Unable to compile class for JSP
 

An error occurred at line: 156 in the jsp file: /murad_scripts/imfIdentifyDefault.jsp

Generated servlet error:

BigDecimal cannot be resolved to a type
 

An error occurred at line: 156 in the jsp file: /murad_scripts/imfIdentifyDefault.jsp

Generated servlet error:

BigDecimal.ROUND_HALF_UP cannot be resolved to a type
 
 

	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)

	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)

	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

	com.moximedia.aims.servlet.filter.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:58)

	net.geocortex.imf.security.http.AuthorizationFilter.doFilter(AuthorizationFilter.java:147)
 
 

root cause 
 

org.apache.jasper.JasperException: Unable to compile class for JSP
 

An error occurred at line: 156 in the jsp file: /murad_scripts/imfIdentifyDefault.jsp

Generated servlet error:

BigDecimal cannot be resolved to a type
 

An error occurred at line: 156 in the jsp file: /murad_scripts/imfIdentifyDefault.jsp

Generated servlet error:

BigDecimal.ROUND_HALF_UP cannot be resolved to a type
 
 

	org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)

	org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)

	org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)

	org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)

	org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)

	org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)

	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)

	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)

	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

	com.moximedia.aims.servlet.filter.ResponseHeaderFilter.doFilter(ResponseHeaderFilter.java:58)

	net.geocortex.imf.security.http.AuthorizationFilter.doFilter(AuthorizationFilter.java:147)
 
 

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
 
 

--------------------------------------------------------------------------------
 

Apache Tomcat/5.5.17

Open in new window

0
 
LVL 16

Assisted Solution

by:Peter Kwan
Peter Kwan earned 125 total points
Comment Utility
Hi, bworld.

You need to import the BigDecimal class like this:

<%page import="java.math.BigDecimal" %>
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:bworld
Comment Utility
How I use output.print with BigDecimal statement ?

How I can use BigDecimal statement to represent values of variables ?

I need an examples for that
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
Comment Utility
0
 

Author Comment

by:bworld
Comment Utility
I need an example with JSP for that

For example if I have this variable
vr_Avg = 89.996527

I want to show like
89.99

How ?
0
 
LVL 92

Assisted Solution

by:objects
objects earned 250 total points
Comment Utility
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

743 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

13 Experts available now in Live!

Get 1:1 Help Now