recode function
Dieser Commit ist enthalten in:
Ursprung
5f10f39719
Commit
c38e6d4276
5 geänderte Dateien mit 69 neuen und 21 gelöschten Zeilen
4
.idea/go-thousands.iml
Normale Datei
4
.idea/go-thousands.iml
Normale Datei
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
</module>
|
|
@ -4,9 +4,7 @@
|
||||||
<option name="autoReloadType" value="ALL" />
|
<option name="autoReloadType" value="ALL" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="d5f54382-616d-41b2-b8f9-53d04e37d644" name="Changes" comment="first version">
|
<list default="true" id="d5f54382-616d-41b2-b8f9-53d04e37d644" name="Changes" comment="switch back changes" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
||||||
</list>
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
@ -32,28 +30,59 @@
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"DefaultGoTemplateProperty": "Go File",
|
"DefaultGoTemplateProperty": "Go File",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||||
"WebServerToolWindowFactoryState": "false",
|
"WebServerToolWindowFactoryState": "false",
|
||||||
"go.import.settings.migrated": "true",
|
"go.import.settings.migrated": "true",
|
||||||
"last_opened_file_path": "/var/www/GoProjects/oldperl/go-thousands",
|
"last_opened_file_path": "/var/www/GoProjects/oldperl/go-thousands",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)"
|
"node.js.selected.package.eslint": "(autodetect)"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
|
<component name="RunManager">
|
||||||
|
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
|
||||||
|
<module name="go-thousands" />
|
||||||
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
|
<kind value="FILE" />
|
||||||
|
<directory value="$PROJECT_DIR$" />
|
||||||
|
<filePath value="$PROJECT_DIR$" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
|
||||||
|
<module name="go-thousands" />
|
||||||
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
|
<kind value="DIRECTORY" />
|
||||||
|
<directory value="$PROJECT_DIR$" />
|
||||||
|
<filePath value="$PROJECT_DIR$" />
|
||||||
|
<framework value="gotest" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value="init" />
|
<MESSAGE value="init" />
|
||||||
<MESSAGE value="first version" />
|
<MESSAGE value="first version" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="first version" />
|
<MESSAGE value="switch back changes" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="switch back changes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="VgoProject">
|
<component name="VgoProject">
|
||||||
<settings-migrated>true</settings-migrated>
|
<settings-migrated>true</settings-migrated>
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
||||||
module gitport.de/oldperl/go-thousands
|
module gitport.de/oldperl/go-thousands
|
||||||
|
|
||||||
go 1.24
|
go 1.24
|
||||||
|
|
||||||
|
require golang.org/x/text v0.26.0
|
||||||
|
|
2
go.sum
Normale Datei
2
go.sum
Normale Datei
|
@ -0,0 +1,2 @@
|
||||||
|
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||||
|
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
19
thousands.go
19
thousands.go
|
@ -2,12 +2,19 @@ package thousands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
language2 "golang.org/x/text/language"
|
||||||
|
"golang.org/x/text/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Separate(Number interface{}, language ...string) (string, error) {
|
func Separate(Number interface{}, language ...string) (string, error) {
|
||||||
|
|
||||||
switch Number.(type) {
|
lang := map[string]string{"de": "German", "en": "English"}
|
||||||
|
useLang := lang[language[0]]
|
||||||
|
|
||||||
|
p := message.NewPrinter(language2.Make(useLang))
|
||||||
|
formattedNumber := ""
|
||||||
|
|
||||||
|
switch n := Number.(type) {
|
||||||
case int:
|
case int:
|
||||||
case int8:
|
case int8:
|
||||||
case int16:
|
case int16:
|
||||||
|
@ -17,9 +24,13 @@ func Separate(Number interface{}, language ...string) (string, error) {
|
||||||
case float64:
|
case float64:
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf("no valid number format")
|
return "", fmt.Errorf("%T is no valid number format", n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
formattedNumber = p.Sprintf("%f", Number)
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
formattedNumber := fmt.Sprintf("%.2f", Number)
|
formattedNumber := fmt.Sprintf("%.2f", Number)
|
||||||
|
|
||||||
if len(language) < 1 {
|
if len(language) < 1 {
|
||||||
|
@ -95,6 +106,6 @@ func Separate(Number interface{}, language ...string) (string, error) {
|
||||||
|
|
||||||
return formattedNumber, nil
|
return formattedNumber, nil
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
return formattedNumber, nil
|
return formattedNumber, nil
|
||||||
}
|
}
|
||||||
|
|
Laden …
In neuem Issue referenzieren