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 6771831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:28:45+00:00 2026-05-26T15:28:45+00:00

I am trying to implement a Currency formater class for different Currencies like Euro,

  • 0

I am trying to implement a Currency formater class for different Currencies like Euro, Doller etc.
I have tried to create an abstract class and want to extend Euro and Doller classes from this class.

As I am new to PHP and don’t know if this is a better way to implement the idea like this.

  abstract class Currency {
      private $name;
      private $symbol;
      private $decimal;
      private $decimal_point;
      private $thousand_sep;

      function __construct() {      
      }

      function setName($name) {
          $this->name = $name;
      }
      function getName() {
          return $this->name;
      }

      function setSymbol($symbol) {
          $this->symbol = $symbol;
      }
      function getSymbol() {
          return $symbol;
      }

      function setDecimal($decimal) {
          $this->decimal = $decimal;
      }
      function getDecimal() {
          return $this->decimal;
      }

      function setDecimalPoint($decimal_point) {
          $this->decimal_point = $decimal_point;
      }
      function getDecimalPoint() {
          $this->decimal_point;
      }

      function setThousandSeprator($thousand_sep) {
          $this->thousand_sep = $thousand_sep;
      }
      function getThousandSeprator() {
          return $this->thousand_sep;
      }

      function display() {
          return $this->symbol . number_format($this->amount, $this->decimal, $this->decimal_point, $this->thousand_sep);
      }
  }
  • 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-05-26T15:28:46+00:00Added an answer on May 26, 2026 at 3:28 pm

    I don’t think you need all those setters, as separators, decimal points and such won’t change during formatter lifetime. If all you want your class to do is to format currency, I don’t think you need all the getters either.

    If your class is responsible only for formatting, I don’t think you should keep value as a class field; maybe better just pass it to display() as an argument.

    How about something like this:

    abstract class CurrencyFormatter {
        protected $name;
        protected $symbol;
        protected $decimal;
        protected $decimal_point;
        protected $thousand_sep;
    
        function format($amount) {
            return $this->symbol . number_format($amount, $this->decimal, $this->decimal_point, $this->thousand_sep);
        }
    }
    
    class EuroFormatter extends CurrencyFormatter {
        public function __construct() {
            $this->name = "Euro";
            $this->symbol = "E";
            $this->decimal = 2;
            $this->decimal_point = ".";
            $this->thousand_sep = ",";
    
        }
    }
    

    Then, you can use it like this:

    $formattedAmount = new EuroFormatter()->format(123);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so i'm currently trying to implement a currency conversion script using Jquery, curl, ajax
SetFocus I'm trying implement the above Se Focus code in a Class Library that
I have this weird kind of error. I am trying implement basic Euclidean algorithm
Trying to implement what I thought was a simple concept. I have a user
I am trying to implement paypal express checkout using rails. I have read at
I am trying to implement a tag cloud like Amazon.co.uk see here . my
I'm trying to create a gift wrapping module for Drupal commerce. I have created
Im trying to implement pagination using multiple searching criteria. Supposed I Have student table.
Trying to implement the following behavior on an iPad. I have a map-centric application
Trying to implement a timer for my game that I'm making. I have a

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.