Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Control the digits after decimal point in float numbers

Posted on 2009-04-06
11
Medium Priority
?
1,840 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
11 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 24075050
use BigDecimal!
0
 
LVL 26

Accepted Solution

by:
ksivananth earned 500 total points
ID: 24075056
for e.g.,

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

Author Comment

by:bworld
ID: 24075106
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 16

Assisted Solution

by:Peter Kwan
Peter Kwan earned 500 total points
ID: 24075362
Hi, bworld.

You need to import the BigDecimal class like this:

<%page import="java.math.BigDecimal" %>
0
 

Author Comment

by:bworld
ID: 24084889
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 1000 total points
ID: 24123754
0
 

Author Comment

by:bworld
ID: 24129841
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 1000 total points
ID: 24133467
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

715 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