Add a utility function to get query responses to Decimal.
See original GitHub issueimport {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:
- Created 2 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@webmaster128 both decodeCosmosSdkDecFromProto and MintExtension from #969 working fine. decodeCosmosSdkDecFromProto response.toString() giving required result.
Please also note https://github.com/cosmos/cosmos-sdk/issues/10863 if you care about the future of Decimals in Cosmos SDK.