Giter Site home page Giter Site logo

pricer's Introduction

Golang Pricer - parser for money string

Build Status GoDoc Software License

This stable version

Testing

type ParseTest struct {
    source        string
    price         string
    price_int     int
    price_int64   int64
    price_float64 float64
    price_type    string
}

var priceTests = []ParseTest{
    {"1 790  руб.",      "1790",    1790, 1790, 1790,    "RUB"},
    {"1 790,20  руб.",   "1790.20", 1790, 1790, 1790.20, "RUB"},
    {"1 790,20  руб.2",  "1790.20", 1790, 1790, 1790.20, "RUB"},
    {"1 790,20",         "1790.20", 1790, 1790, 1790.20, "DEFAULT_TYPE"},
    {"1 790,20€",        "1790.20", 1790, 1790, 1790.20, "EUR"},
    {"1 790.20.123€",    "1790.20", 1790, 1790, 1790.20, "EUR"},
    {"1 790.20,123 EUR", "1790.20", 1790, 1790, 1790.20, "EUR"},
}

Installation

$ go get github.com/mantyr/pricer

Example

package main

import (
    "github.com/mantyr/pricer"
    "fmt"
)

func main() {
    price := pricer.NewPrice()
    price.SetDefaultType("DEFAULT_TYPE")

    price.Parse("1 179.20 $")

    fmt.Println(price.Get())        // print "1179.20"
    fmt.Println(price.GetInt())     // print "1179"
    fmt.Println(price.GetInt64())   // print "1179"
    fmt.Println(price.GetFloat64()) // print "1179.2"
    fmt.Println(price.GetType())    // print "USD"

    price.Parse("1 179.21 руб.")

    fmt.Println(price.Get())        // print "1179.21"
    fmt.Println(price.GetInt())     // print "1179"
    fmt.Println(price.GetInt64())   // print "1179"
    fmt.Println(price.GetFloat64()) // print "1179.21"
    fmt.Println(price.GetType())    // print "RUB"

    price.Parse("1 179.21")

    fmt.Println(price.Get())        // print "1179.21"
    fmt.Println(price.GetInt())     // print "1179"
    fmt.Println(price.GetInt64())   // print "1179"
    fmt.Println(price.GetFloat64()) // print "1179.21"
    fmt.Println(price.GetType())    // print "DEFAULT_TYPE"
}

Author

Oleg Shevelev

pricer's People

Contributors

mantyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.