question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a utility function to get query responses to Decimal.

See original GitHub issue
import {Tendermint34Client} from "@cosmjs/tendermint-rpc";
import {createProtobufRpcClient, QueryClient} from "@cosmjs/stargate";
import {QueryClientImpl as MintQueryClientImpl} from 'cosmjs-types/cosmos/mint/v1beta1/query';
import { Decimal } from "@cosmjs/math";

       const tendermintClient = await Tendermint34Client.connect("rpc.cosmos....");
       const queryClient = new QueryClient(tendermintClient);
       const rpcClient = createProtobufRpcClient(queryClient);
       const queryService = new MintQueryClientImpl(rpcClient);
       const response = await queryService.Inflation({});
       console.log(response.inflation)

Here response.infaltion returns a uint8array.

        let decoder = new TextDecoder('utf8');
        let decimalString = Decimal.fromAtomics(decoder.decode(response.inflation),18).toString()

Is there another way to do this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
blackpanther1881commented, Jan 6, 2022

@webmaster128 both decodeCosmosSdkDecFromProto and MintExtension from #969 working fine. decodeCosmosSdkDecFromProto response.toString() giving required result.

1reaction
webmaster128commented, Jan 5, 2022

Please also note https://github.com/cosmos/cosmos-sdk/issues/10863 if you care about the future of Decimals in Cosmos SDK.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Utility Functions for Use in Productions
Returns val rounded off to n digits after the decimal point. If n is not provided (that is, Round(val)) the function drops the...
Read more >
SQL get decimal with only 2 places with no round
You could accomplish this via the ROUND() function using the length ... 2 indicates that the value will be rounded to two decimal...
Read more >
Number functions - PowerQuery M - Microsoft Learn
Decimal.From, Returns a decimal number value from the given value. Double.From, Returns a Double number value from the given value.
Read more >
Conversion functions | BigQuery - Google Cloud
Cast syntax is used in a query to indicate that the result type of an expression should be converted to some other type....
Read more >
apex - How to convert a number into a formatted string?
I can call the Utility function from any apex class and it will format my Decimal value into the string with $1,123.00.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found