Giter VIP home page Giter VIP logo

Comments (4)

eager7 avatar eager7 commented on May 23, 2024

this is my temporary solution:

import 	"github.com/shopspring/decimal"

// formatDuration formats a duration
func formatDuration(i time.Duration, millisecondSep string, numberOfMillisecondDigits int) (s string) {
	// Parse hours
	var hours = int(i / time.Hour)
	var n = i % time.Hour
	if hours < 10 {
		s += "0"
	}
	s += strconv.Itoa(hours) + ":"

	// Parse minutes
	var minutes = int(n / time.Minute)
	n = i % time.Minute
	if minutes < 10 {
		s += "0"
	}
	s += strconv.Itoa(minutes) + ":"

	// Parse seconds
	var seconds = int(n / time.Second)
	n = i % time.Second
	if seconds < 10 {
		s += "0"
	}
	s += strconv.Itoa(seconds) + millisecondSep

	// Parse milliseconds
	var milliseconds = float64(n/time.Millisecond) / float64(1000)
	// PCT 解决精度丢失问题
	decimalMs := decimal.NewFromFloat(milliseconds)
	round := decimalMs.RoundFloor(int32(numberOfMillisecondDigits)).InexactFloat64()
	s += fmt.Sprintf("%."+strconv.Itoa(numberOfMillisecondDigits)+"f", round)[2:]
	// s += fmt.Sprintf("%."+strconv.Itoa(numberOfMillisecondDigits)+"f", milliseconds)[2:]
	return
}

from go-astisub.

asticode avatar asticode commented on May 23, 2024

I've pushed a fix on master based on your provided test data, could you confirm your problem is now resolved?

Let me know whether you need a tag 👍

from go-astisub.

eager7 avatar eager7 commented on May 23, 2024

I've pushed a fix on master based on your provided test data, could you confirm your problem is now resolved?

Let me know whether you need a tag 👍

There's nothing wrong with my test,tks

from go-astisub.

asticode avatar asticode commented on May 23, 2024

Closing this issue then 👍

from go-astisub.

Related Issues (20)

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.