-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split thousands Returns several 0 #11
Comments
@Ballasi You have added numbers upto |
Or we can simply use it as string. We aren't using it for calculation. The commas can be removed and string will be split by decimal point. |
Can you give me a code snippet as example? That sounds like a bug for the crate, might be interested to investigate.
BigFloat has relative precision, which means that it's always 40 digits, but relatively to the known spectrum. For instance, However, this has limitations since it cannot store
I had though of that before, but sadly you cannot store numbers like You can "inverse" the input of the decimal part (e.g., for the example above,
Same here, it's not really the best idea to store number as strings, I don't reject that possibility but it really is not that great, and makes the crate quite expensive to use, which I tend to avoid. I know that the author of What do you think? |
Here, the is_zero only works when you get exponents around 100+. So, it gives unnecessry zeroes.
why not? it will just be two strings with
I don't know if it can really be viewed as number when the only thing we take i individual digits. It's similar to Phone Numbers which has digits but no meaning to operation like addition and such. About expensive, will it really be so expensive? But yes, if there is type with unlimited precision, then that would be good. But I still think string might be better. Processing it would be easier as it's easy to get individual characters from them without much operation. |
Curious, thanks for the code snippet, I'll investigate that! Thanks!
I was talking about using
True that, the only main "operation" that is used is
I am mostly thinking of memory expensive and parsing intensive. Like you pass as arg a i8 which will be turned into a String which will then be processed, create new string on the heap, etc. etc.
As talked on Reddit, I am more keen on using something as case number {
"1" => "one",
"2" => "two",
...
} you can have And on top of that it ensures the data type passed is numbers and not junk. What do you think of this @hexofyore? |
I was mainly thinking in terms of the library being used for when user inputs value which will always be string and later be parsed to whatever. But, it can likely be result of some calculation. And, I didn't think about that mapping. This makes turning to string not so better. Vec is the best of world but we still need to turn the number to individual digits and store them as vector. I think we can simply use arbitrary precision integers and maybe we can think of handling zeroes after decimal point somehow. While any method is doable, I am not so sure which is better. method. I am just beginner and while I may get things done, I don't think I can do it right way. You choose one and maybe I will try it. Anyway, I think I will first complete nepali addition. And, what do you think of adding to_numeral? Like, '12345' is '१२३४५' in devanagari. |
This is true for the context of the binary, which is mainly just a demo of the library. The main "product" of this num2words git is the library itself which supports both numbers and strings. And experience shows that the main usage of the lib is via numbers rather than string.
I'll preferably go with the
And that's totally okay! Your help is already greatly appreciated and I'll be here to help in case there is anything! That's firstly very kind of you to take your time to take part in this conversation. I'll be happy to receive a PR with work for
I wonder rather than using I am also wondering if that is supposed to be the other way around, I mean having For now focus on |
a quick fix about extra zeros is to truncate the decimals on each check. How much does this hit the performance? Idk, because BigFloat is a Copy-Type so it would be best to benchmark first before anything fn en_miles(&self, mut num: BigFloat) -> Vec<u64> {
// Doesn't check if BigFloat is Integer only
let mut thousands = Vec::new();
let mil = 1000.into();
num = num.abs();
while !num.int().is_zero() {
// Insert in Low Endian
thousands.push((num % mil).to_u64().expect("triplet not under 1000"));
num /= mil; // DivAssign
}
thousands
} |
Related issue: Ballasi#11
The
!num.is_zero()
doesn't work properly for float. The division isn't accurate so the exponent reduces on each division and eventually reaches 0. I think there is no need to use float. The input string can be split by.
and both be represented as u128 which gives precision of 38 digits which I think is equal to the Bigfloat.The text was updated successfully, but these errors were encountered: