Golang get decimal separator for current culture
Golang get decimal separator for current culture
Is there a way in Golang to get the current OS decimal separator in windows?
I know that in the Geographic area settings in control panel you can assign your custom decimal separator, so there must be a way to get this value... or no?
I want to use fmt.Printf() and format any float with the OS current decimal symbol.
1 Answer
1
I want to use fmt.Printf() and format any float with the OS current decimal symbol.
To get the current language OS, you might use a cross platform package such as https://github.com/cloudfoundry-attic/jibber_jabber
To print localized texts you might use the text package available here https://godoc.org/golang.org/x/text
Example
package main
import (
"fmt"
"github.com/cloudfoundry/jibber_jabber"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
func main()
userLanguage, err := jibber_jabber.DetectLanguage()
if err != nil
panic(err)
fmt.Println("Language:", userLanguage)
tagLanguage := language.Make(userLanguage)
fmt.Println("Language:", tagLanguage)
p := message.NewPrinter(language.BritishEnglish)
p.Printf("There are %v flowers in our garden.n", 1500)
p := message.NewPrinter(tagLanguage)
p.Printf("There are %v flowers in our garden.n", 1500)
As you can see you don t directly use the fmt
package anymore, instead you have to create a Printer
and use this one to display the texts appropriately.
fmt
Printer
to get more details about this package usage you can read https://phraseapp.com/blog/posts/internationalization-i18n-go/
Is there a way in Golang to get the current OS decimal separator in windows?
I have not been able to determine how to extract this information from the text package.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.