Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exponent.test.ts 1.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { describe, it, expect } from 'vitest';
  2. import { exponentialToNumberString, numberToExponential } from '../src/exponent';
  3. describe('numberToExponential', () => {
  4. it('converts 0 to 0e+0', () => {
  5. expect(numberToExponential(0)).toBe('0e+0');
  6. });
  7. it('converts "0" to 0e+0', () => {
  8. expect(numberToExponential('0')).toBe('0e+0');
  9. });
  10. it('converts "00000000000000000" to 0e+0', () => {
  11. expect(numberToExponential('00000000000000000')).toBe('0e+0');
  12. });
  13. it('converts 1 to 1e+0', () => {
  14. expect(numberToExponential(1)).toBe('1e+0');
  15. });
  16. it('converts "0.1" to 1e-1', () => {
  17. expect(numberToExponential('0.1')).toBe('1e-1');
  18. });
  19. it('converts "0.10" to 1e-1', () => {
  20. expect(numberToExponential('0.10')).toBe('1e-1');
  21. });
  22. it('converts "1" to 1e+0', () => {
  23. expect(numberToExponential('1')).toBe('1e+0');
  24. });
  25. it('converts "10" to 1e+1', () => {
  26. expect(numberToExponential('10')).toBe('1e+1');
  27. });
  28. it('converts "100" to 1e+2', () => {
  29. expect(numberToExponential('100')).toBe('1e+2');
  30. });
  31. it('converts "0100" to 1e+2', () => {
  32. expect(numberToExponential('0100')).toBe('1e+2');
  33. });
  34. it('converts "1234567890" to 1.23456789e+9', () => {
  35. expect(numberToExponential('1234567890')).toBe('1.23456789e+9');
  36. });
  37. it('converts "1234567890.1234567890" to 1.234567890123456789e+9', () => {
  38. expect(numberToExponential('1234567890.1234567890')).toBe('1.234567890123456789e+9');
  39. });
  40. it('converts "1e+100" to 1e+100', () => {
  41. expect(numberToExponential('1e+100')).toBe('1e+100');
  42. });
  43. it('converts "12.3e+10" to 1.23e+11', () => {
  44. expect(numberToExponential('12.3e+10')).toBe('1.23e+11');
  45. });
  46. });
  47. describe('exponentialToNumberString', () => {
  48. it('converts 1e+0 to 1', () => {
  49. expect(exponentialToNumberString('1e+0')).toBe('1');
  50. });
  51. it('converts 1e+1 to 10', () => {
  52. expect(exponentialToNumberString('1e+1')).toBe('10');
  53. });
  54. it('converts 1.23e+1 to 12.3', () => {
  55. expect(exponentialToNumberString('1.23e+1')).toBe('12.3');
  56. });
  57. });