Search code examples
google-chromejsputf-8jstl

how to fix dollar symbols ($) that change to (¤) in my jsp page?


I have a code that displays the $168,00 symbol on the jsp page, but it changes to the ¤168,00 symbol, but when I try run my project using public IP or using my IP in another client, the $ symbol doesn't change to ¤, there is no problem

I have tried using type="currency" and currencySymbol="$" it works, but when I use currencySymbol="$" it affects the results of the functions I use. previously I only used type="currency" and it worked, but when I commit my project the $ symbol changed to ¤

But In other browsers it works fine Mozilla ($168,00)

Iam using Google Chrome Version 76.0.3809.132 (Official Build) (64-bit)

I declare character encoding in the headers using

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@taglib uri="http://sargue.net/jsptags/time" prefix="javatime"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
value='<fmt:formatNumber type="currency" value="${project.Amount}" minFractionDigits="2" maxFractionDigits="2" />'

Solution

  • Missing character-encoding declaration

    You likely have neglected to specify a character encoding for your JSP page.

    If you fail to specify a character encoding within your page headers, the web browsers are forced to guess or fall back to some default. So your results will vary by browser and by user’s settings within that browser. Characters may be misinterpreted as being other characters.

    ¤ versus $

    The currency sign character (¤) replaces the dollar sign ($) in some national variants of ASCII. So what you are seeing is likely a feature, not a bug.

    In Unicode, use:

    • hex 24, decimal 36, for dollar sign.
    • hex A4, decimal 164, for CURRENCY SIGN character.

    Solution: Specify your character encoding

    The solution is simple, and should be your normal operating procedure in all web work:

    • Pick a character encoding for the content of your pages.
    • Use that character encoding when editing the source code of that content.
    • Declare that character encoding appropriately: web server settings, headers of your page.
    • Be rigorous in verifying that all parts of your content have source code with characters that were indeed encoded in that declared encoding.

    Be sure that no tools along your toolchain are fighting you, using and/or declaring some other encoding. Use a “developer edition” of a powerful web browser such as Firefox to examine your resulting page content.

    UTF-8

    Nowadays, the go-to character encoding is UTF-8. This encoding can represent text using any of the over 110,000 characters defined in Unicode. Every character has exactly one single permanently assigned number, so you will have no more surprises.

    UTF-16 is a more space-efficient encoding for content made heavily of CJK text. But security flaws in various implementations have lead to this encoding no longer being recommended for web work.

    Resources

    If you are not savvy with character sets and character encodings, see:

    Search Stack Overflow for more info, as this topic has been addressed many many times already.

    Specify your human language

    On a similar note, your web content can and should declare the human language (English, French, Swahili, and such) used in writing its content.