Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:52:06+00:00 2026-06-11T01:52:06+00:00

I have seen this question already answered here but when I tried the same

  • 0

I have seen this question already answered here but when I tried the same approach, it did not work. Here’s my code:

package linear_programming.matrix;

import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.text.NumberFormat;

/**
 *
 * @author Jevison7x
 */
public final class MatrixOperations<T extends Number>
{
    /**
 * This method round's off decimal numbers to two decimal places.
 * @param d The decimal number to be rounded off.
     * @param decPlaces The number of decimal places to round off.
 * @return the rounded off decimal number.
 */
public static double roundOff(double d, int decPlaces)
{ 
        if(decPlaces < 0)
            throw new IllegalArgumentException("The number of decimal places cannot be less than 0.");
        else
        {
            String places = "";
            for(int i = 0; i < decPlaces; i++)
            places += "0";
            NumberFormat nf = new DecimalFormat("0."+places);
            return Double.parseDouble(nf.format(d));
        }
}
}

Here is my tld file:

<?xml version="1.0" encoding="UTF-8"?>
<taglib 
    version="2.1" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">

    <display-name>Custom Functions</display-name>
    <tlib-version>1.0</tlib-version>
    <short-name>func</short-name>
    <uri>/WEB-INF/tlds/Functions</uri>

    <function>
        <name>roundOff</name>
        <function-class>linear_programming.matrix.MatrixOperations</function-class>
        <function-signature>double roundOff(double int)</function-signature>
    </function>
</taglib>

Then here is my JSP file:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="/WEB-INF/tlds/Functions" prefix="func"%>
<table>
    <c:forEach var="Msegment" items="${multipliedSegments}" varStatus="segmentCount">
    <tr>
        <td>X<sub>${segmentCount.count}</sub><sup>T</sup>X<sub>${segmentCount.count}</sub>=</td>
        <td>
            <table border="1">
        <c:forEach var="row" items="${Msegment}">
                <tr>
            <c:forEach var="col" items="${row}">
                <td>${col}</td><!-- Iwant to invoke the static method here -->
            </c:forEach>
                </tr>
        </c:forEach>
            </table>
        </td>
    </tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td></tr>
    </c:forEach>
</table>

I just want to invoke the static method

roundOff(double d, int decPlaces)

and pass the variable

${col} 

as the double parameter – d and then any number can go for decPlaces.
Any help would be highly appreciated thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:52:08+00:00Added an answer on June 11, 2026 at 1:52 am
     ${func:roundOff(col, 1)}
    

    should do. But AFAIK, the signature in the taglib file should be

    double roundOff(double, int)
                          ^--- comma here.
    

    If this doesn’t work, then mention the exact error message you get, instead of just saying “it doesn’t work”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have seen this question already but it does not explain it so that
I have seen many answers for this type of question but its not related
I have seen this question posted here, but always, the answer is that the
In Microsoft SQL Server: I have seen this question several times, but can't see
Recently I have seen this code in a WebSite, and my question is the
This question may seem a little bit stackoverflow-implementation specific, but I have seen a
This question seems to have been asked a lot, but I haven't seen an
I have seen this question floating around the internet, but I haven't found a
I have seen this similar question on SO in a few places but all
I've already seen this question but it's been asked over a year ago. Perhaps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.