嗨,我试图收回BigDecimal唯一的数据。以下示例对我期望的内容进行成像
1.23 -> 123
123.99 -> 12399
1.345 -> 1345
0.23 -> 23
我尝试使用DecimalFormat,但我没有想法哪种模式是正确的。
答案 0 :(得分:0)
import "angular-mocks/ngMock";
import * as angular from "angular";
import {inject, TestBed} from "@angular/core/testing";
import {Inject, Injectable, FactoryProvider} from "@angular/core";
import {AngularJSService} from "angularjs/angularjs.service" // angularjs service which is upgraded and injected in ExampleService angular service
// upgrading angular js service to make it possible to inject into angular services/components
const UpgradedProvider: FactoryProvider = {
provide: AngularJSService,
useFactory: ($injector: angular.auto.IInjectorService) => {$injector.get('AngularJSService')},
deps: ['$injector']
};
// this is angular service which has upgraded angularjs service in dependency
@Injectable()
class ExampleService {
public name: string = 'Example Service';
constructor(angularJSService: AngularJSService) {
// injecting angular js service
}
}
describe('Angular Example Test Suite ', () => {
let $injector: angular.auto.IInjectorService;
beforeEach(() => {
// init angular js module for test and define upgraded angular js service in this module
angular.module('ExampleTest', []).service('AngularJSService', AngularJSService);
});
beforeEach(angular.mock.module('ExampleTest'));
beforeEach(angular.mock.inject((_$injector_: ng.auto.IInjectorService) => {
$injector = _$injector_;
}));
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{
provide: '$injector',
useFactory: () => $injector,
deps: []
},
UpgradedProvider,
ExampleService
]
});
});
it('should inject ExampleService', inject([ExampleService], (exampleService: ExampleService) => {
chai.assert.isDefined(exampleService);
}));
});
你可以将它转换为数字类型,但它有点危险,因为大小数可能是一个大数字,它可能不适合int。