func (c *Currency) FractionalTotal() int {
	cFrac := c.Fractional
	if c.Main < 0 {
		cFrac = -cFrac
	}
	return ((c.Main * int(c.FUShare)) + cFrac)
}
FractionalTotal returns the total value in fractional int.
package currency
import (
	"errors"
	"math"
	"regexp"
	"strconv"
	"strings"
)
var (
	ErrMismatchCurrency = errors.New("currencies do not match")
	ErrInvalidCurrency = errors.New("invalid currency value provided")
	ErrInvalidFUS = errors.New("invalid functional unit share provided")
)
var replacer = regexp.MustCompile(`([^0-9.\-\+])`)
const (
	replaceWith = ""
)
type Currency struct {
	Code string `json:"code,omitempty"`
	Symbol string `json:"symbol,omitempty"`
	Main int `json:"main,omitempty"`
	Fractional int `json:"fractional,omitempty"`
	FUName string `json:"fuName,omitempty"`
	FUShare uint `json:"fuShare,omitempty"`
	fuDigits int `json:"fuDigits,omitempty"`
	magnitude float64 `json:"magnitude,omitempty"`
}
func New(main int, fractional int, code, symbol, funame string, fushare uint) (*Currency, error) {
	if fushare == 0 {
		return nil, ErrInvalidFUS
	}
	if main != 0 && fractional < 0 {
		fractional = -fractional
	}
	fus := int(fushare)
	m := main + (fractional / fus)
	f := fractional % fus
	fudigits := digits(fus - 1)
	mag := float64(5.0)
	for i := 0; i < fudigits-1; i++ {
		mag /= 10
	}
	return &Currency{
		Code:       code,
		Symbol:     symbol,
		Main:       m,
		Fractional: f,
		FUName:     funame,
		FUShare:    fushare,
		fuDigits:   fudigits,
		magnitude:  mag,
	}, nil
}
func NewFractional(ftotal int, code, symbol, funame string, fushare uint) (*Currency, error) {
	if fushare == 0 {
		return nil, ErrInvalidFUS
	}
	fus := int(fushare)
	m := ftotal / fus
	f := (ftotal % fus)
	if m < 0 {
		f = -f
	}
	fudigits := digits(fus - 1)
	mag := float64(5.0)
	for i := 0; i < fudigits-1; i++ {
		mag /= 10
	}
	return &Currency{
		Code:       code,
		Symbol:     symbol,
		Main:       m,
		Fractional: f,
		FUName:     funame,
		FUShare:    fushare,
		fuDigits:   fudigits,
		magnitude:  mag,
	}, nil
}
func ParseString(value string, code, symbol, funame string, fushare uint) (*Currency, error) {
	str := replacer.ReplaceAllString(value, replaceWith)
	f, err := strconv.ParseFloat(str, 64)
	if err != nil {
		return nil, err
	}
	return ParseFloat64(f, code, symbol, funame, fushare)
}
func ParseFloat64(value float64, code, symbol, funame string, fushare uint) (*Currency, error) {
	if fushare == 0 {
		return nil, ErrInvalidFUS
	}
	fus := int(fushare)
	fudigits := digits(fus - 1)
	mag := float64(5.0)
	for i := 0; i < fudigits-1; i++ {
		mag /= 10
	}
	ftotal := round(value*float64(fushare), mag)
	main := ftotal / fus
	fractional := (ftotal % fus)
	if main < 0 {
		fractional = -fractional
	}
	m := main + (fractional / fus)
	f := fractional % fus
	return &Currency{
		Code:       code,
		Symbol:     symbol,
		Main:       m,
		Fractional: f,
		FUName:     funame,
		FUShare:    fushare,
		fuDigits:   fudigits,
		magnitude:  mag,
	}, nil
}