Browse Source

Adapt amount of digits

banano
codesoap 3 months ago
parent
commit
6ab8733b7d
  1. 4
      account_info.go
  2. 4
      cmd/atto-safesign/util.go
  3. 4
      cmd/atto/util.go

4
account_info.go

@ -66,9 +66,9 @@ func getBalanceAfterSend(oldBalance string, amount string) (*big.Int, error) { @@ -66,9 +66,9 @@ func getBalanceAfterSend(oldBalance string, amount string) (*big.Int, error) {
func nanoToRaw(amountString string) (*big.Int, error) {
i := strings.Index(amountString, ".")
missingZerosUntilRaw := 30
missingZerosUntilRaw := 29
if i > -1 {
missingZerosUntilRaw = 31 + i - len(amountString)
missingZerosUntilRaw = 30 + i - len(amountString)
amountString = amountString[:i] + amountString[i+1:] // Remove "."
}
amountString += strings.Repeat("0", missingZerosUntilRaw)

4
cmd/atto-safesign/util.go

@ -89,12 +89,12 @@ func appendLineToFile(in []byte) error { @@ -89,12 +89,12 @@ func appendLineToFile(in []byte) error {
}
func rawToNanoString(raw *big.Int) string {
rawPerNano, _ := big.NewInt(0).SetString("1000000000000000000000000000000", 10)
rawPerNano, _ := big.NewInt(0).SetString("100000000000000000000000000000", 10)
absRaw := big.NewInt(0).Abs(raw)
integerDigits, fractionalDigits := big.NewInt(0).QuoRem(absRaw, rawPerNano, big.NewInt(0))
res := integerDigits.String()
if fractionalDigits.Sign() != 0 {
fractionalDigitsString := fmt.Sprintf("%030s", fractionalDigits.String())
fractionalDigitsString := fmt.Sprintf("%029s", fractionalDigits.String())
res += "." + strings.TrimRight(fractionalDigitsString, "0")
}
if raw.Sign() < 0 {

4
cmd/atto/util.go

@ -20,12 +20,12 @@ func getSeed() (string, error) { @@ -20,12 +20,12 @@ func getSeed() (string, error) {
}
func rawToNanoString(raw *big.Int) string {
rawPerNano, _ := big.NewInt(0).SetString("1000000000000000000000000000000", 10)
rawPerNano, _ := big.NewInt(0).SetString("100000000000000000000000000000", 10)
absRaw := big.NewInt(0).Abs(raw)
integerDigits, fractionalDigits := big.NewInt(0).QuoRem(absRaw, rawPerNano, big.NewInt(0))
res := integerDigits.String()
if fractionalDigits.Sign() != 0 {
fractionalDigitsString := fmt.Sprintf("%030s", fractionalDigits.String())
fractionalDigitsString := fmt.Sprintf("%029s", fractionalDigits.String())
res += "." + strings.TrimRight(fractionalDigitsString, "0")
}
if raw.Sign() < 0 {

Loading…
Cancel
Save